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
In constructor overloading, …………… .
- All constructors must have the same name as that of the class.
- All constructors must have the same number of arguments.
- All constructors must have arguments of type String[] args.
- All constructors must have no arguments.
What is a constructor? Why do you need a constructor?
Explain the statement, "you cannot invoke constructors as normal method calls".
Describe the importance of parameterised constructors.