Top News

Why do we need constructor in Java?

 

Java is an object-oriented language, in which we create and use
objects. A constructor is a piece of code similar to a method. It is
used to create an object and set the initial state of the object.
A constructor is a special function that has same name as class
name.
Without a constructor, there is no other way to create an object.
By default, Java provides a default constructor for every object. If
we overload a constructor then we have to implement default
constructor.

Post a Comment

Previous Post Next Post