Bird
0
0

Which of the following is a valid constructor declaration in Java?

easy📝 Syntax Q3 of 15
Java - Constructors
Which of the following is a valid constructor declaration in Java?
Apublic void Car() {}
Bpublic Car() {}
Cvoid Car() {}
Dpublic static Car() {}
Step-by-Step Solution
Solution:
  1. Step 1: Check constructor syntax rules

    Constructors have no return type and must have the same name as the class.
  2. Step 2: Identify the correct syntax

    public Car() {} has no return type and matches the class name, so it is valid.
  3. Final Answer:

    public Car() {} -> Option B
  4. Quick Check:

    Constructor syntax = No return type, same name [OK]
Quick Trick: Constructors have no return type and match class name [OK]
Common Mistakes:
  • Adding void return type to constructor
  • Using static keyword in constructor
  • Using different name than class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes