Constructors in Java

Constructor Definition:

1. It is called constructor because it constructs the value at the time of object creation.
2. Block of code similar to method.
3. It is called when an object of class is created.
4. At the time of calling constructor, memory for the object is allocated in the memory.
5. It is used to initialize the object.
6. Java compiler created the default constructor if your class doesn't have any constructor.

Rules to Create Constructor:

1. Constructor name must be the same as its class name
2. Must have no return type
3. A Java constructor cannot be abstract, static, final, and synchronized

Types of Constructor:

1. Default or no arguments – Provides default values
2. Parameterized constructor

Constrtuctore Overloading:

having more than one constructor with different parameter lists.

Constructor Vs Method:

Java Constructor Vs Java method

Java Constructor Vs Java method 

To get more details please watch below youtube video and Subscribe the channel.

No comments:

Post a Comment