Object-Oriented Programming · Question 4 · Easy

Which statement about constructors in Java is correct?

  1. A constructor must have the return type void
  2. A constructor is inherited by subclasses
  3. A constructor has the same name as its class and no return type
  4. A constructor can only be called explicitly with a method call
Answer and explanation

Answer: C. A constructor has the same name as its class and no return type

Explanation: A constructor has the class name and no return type, not even void. It runs automatically when an object is created with new, and constructors are not inherited.

Previous: Which OOP feature lets a single reference of a parent type call different… · Next: A Car object contains an Engine object. This "has-a" relationship is best…

Practise object-oriented programming

Try a fresh set of object-oriented programming questions with an explanation after every answer, free and without signing up: Object-Oriented Programming practice. Or sit a full placement mock test.

More object-oriented programming questions

More technical & programming practice

DBMS · SQL · Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps · GenAI Basics · Pseudo-code

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge