Question:

In constructor overloading all constructors should have the same class but with a different set of ________.

Show Hint

Constructors never have a return type. If you see the word \textbf{overloading}, immediately think of \textbf{same name but different parameters}.
  • Access specifiers
  • Classes
  • Return type
  • Parameters
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

Step 1: Understand constructor overloading.
Constructor overloading means defining more than one constructor in the same class. All these constructors have the same class name, because a constructor must always have the same name as the class. However, they must differ from each other in the list of arguments they accept.
Step 2: Recall the rule for overloading.
In Java, overloading is achieved when methods or constructors have the same name but a different parameter list. The difference may be in:
  • number of parameters,
  • type of parameters,
  • or order of parameters.
So, for constructor overloading, the constructors must be distinguished by their parameters.
Step 3: Compare the given options.
  • (A) Access specifiers: Incorrect. Constructors may have different access specifiers, but this is not the basis of overloading.
  • (B) Classes: Incorrect. Constructor overloading happens within the same class, not different classes.
  • (C) Return type: Incorrect. Constructors do not have any return type.
  • (D) Parameters: Correct. Overloaded constructors must differ in their parameter lists.
Step 4: Conclusion.
Therefore, in constructor overloading, all constructors belong to the same class but have a different set of parameters.
Final Answer:Parameters.
Was this answer helpful?
0
0

Top Questions on Object-Oriented Programming

View More Questions