Constructors are used to initialize an object. Constructor’s are called when a method is initialized. Constructors cannot be inherited.
- Constructor has the same name as the class.
- Class can have more than one constructor.
- Constructor can take zero, one, or more parameters.
- Constructor has no return value.
- Constructor is always called with the new operator.
Java
public class Person
{
public Person(String FirstName)
{
this.FirstName = FirstName;
}
}
{
public Person(String FirstName)
{
this.FirstName = FirstName;
}
}