Finally. the component of class we will look at is Constructor. Constructors are used when creating an object of class, and it has a similar format as method. The difference is that it runs when creating an object and it does not have a return value. The syntax of constructor is as follows.
accessModifiers className (parameterList) {
…
}
The value of access modifiers will be something like public and private. Constructors always have the same name as the class name. The code below shows an example of MemberInfo class constructor.
Constructor is used when creating an object with “new”. The following code is an example creating object using MemberInfo constructor.
If you run a constructor using “new”, object is created. In other words, in above code, if you run a MemberInfo() constructor, MemberInfo() object is created and it is assigned to “info” reference. If you create an object, you can use it using a reference refering to the object.