Computer Applications

If the constructor is automatically generated by the compiler, why do you need to define your own constructor?

Java Constructors

3 Likes

Answer

A default constructor does not have any statement inside it. It initializes default values to the instance variables.

If we define our own constructor in a class, we can initialise the instance variables according to our requirements. A parameterised constructor allows the programmer to initialise objects with different values. This is achieved by passing the required values as arguments to the constructor method.

Answered By

1 Like


Related Questions