Constructors in JAVA - Tecnew

Home Ads

Constructors in JAVA

Constructors in JAVA

Share This
The definition of constructors in java is given below.

1. Constructors are used to initialise the instance variables of an object.

2. It must have the same name as that of the class and have no return type.

3. Constructors can be classified into two types.
 They are:  1. Default constructor.
                     2. Parameterized constructor.

4. If you don't define a constructor, then the compiler creates a default constructor. Default constructor do not contain any parameters. Default constructors are created only if there are no constructors defended by us.

5. parameterized constructors are required to pass parameters on creation of objects.

6. Use 'this()' keyword to communicate from one constructor to another constructor in the same class.

7. Use ''super()' kevda to communicate with superclass constructor.

No comments:

Post a Comment