If the constructor is automatically generated by the compiler, why do you need to define your own constructor?
Please answer me correctly
Answers
Answered by
2
If no constructor is defined within the class , java compiler automatically invokes a default constructor that initialises all the fields with their default values .
▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃
╹ Default constructor and parameterized constructor are invoked by the user where default constructors are the constructors that does not have any parameters or argument where does parameterized constructor sar the constructors which can take parameters or arguments
Answered by
0
Hyyy....
In C++, compiler creates a default constructor if we don't define our own constructor (See this). Compiler created default constructor has empty body, i.e., it doesn't assign default values to data members (In java, default constructors assign default values).
Similar questions