Identify the true statement(s).
Statement 1 : When no constructor is written in a class, the compiler creates a default constructor
Statement 2 : The default constructor will implicitly invoke the default / no-argument constructor of the super class
Statement 3 : If a class has a parametrized constructor alone, then the compiler will create the default constructor
Statement 4 : If a class has a parametrized constructor, it is mandatory to write a no-argument constructor
Select one:
1, 2 and 4
1, 2 and 3
1 and 2
2 and 3
Answers
Answered by
3
Answer:
option a is correct as per the rules..
Answered by
3
The correct statements are 1, 2 and 4.
- If a class doesn't support a constructor with no arguments, the modern compiler always generates one. The compiler will solely create a default one if there are no other constructors for the class.
- The compiler typically produces a no-argument default constructor for every distinct class that lacks constructors thereby calling a superclass.
- Having a default constructor is never needed. It is, however, required to provide a no-argument constructor, either expressly declared or by default, whether it is termed explicitly or implicitly.
Similar questions
Geography,
1 month ago
Math,
1 month ago
Computer Science,
2 months ago
Computer Science,
10 months ago
Science,
10 months ago