Bird
0
0

Which of the following constructor declarations is correct for overloading?

easy📝 Syntax Q12 of 15
Java - Constructors

Which of the following constructor declarations is correct for overloading?

public class Car {
    public Car() { }
    public Car(String model) { }
    public Car(int year) { }
    public Car(String model, int year) { }
}
AOnly constructors with one parameter are allowed.
BConstructors must have different names, so this is incorrect.
CAll constructors have different parameter lists, so all are correct.
DConstructors cannot have parameters, so only the first is correct.
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter lists of constructors

    Each constructor has a unique parameter list: no parameters, one String, one int, and two parameters.
  2. Step 2: Verify constructor overloading rules

    Constructors can share the same name but must differ in parameters. This code follows that rule.
  3. Final Answer:

    All constructors have different parameter lists, so all are correct. -> Option C
  4. Quick Check:

    Different parameters = valid overloading [OK]
Quick Trick: Check if parameter lists differ, not constructor names [OK]
Common Mistakes:
  • Thinking constructors need different names
  • Believing constructors cannot have parameters
  • Confusing method overloading rules with constructors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes