Constructors in Java

Basically, a class constructor is a special method used to create an object of a class, and initialize its instance variable. A class can define multiple constructors with different sets of method parameters.

Remember : A constructor must match the name of the class and cannot declare a return value (not even void).

Here are the rules to define constructors :

  1. The name of the constructor must match with the name of the java class;
  2. The constructor doesn’t have a return type (not even void).
One Comment

Leave a Reply to sureunit Cancel reply

Your email address will not be published.