Object-Oriented Programming · Question 8 · Medium
Which statement about abstract classes and interfaces in Java is correct?
- An interface can declare constructors
- An abstract class can be instantiated directly with new
- An abstract class can have constructors, but an interface cannot
- A Java class can extend more than one abstract class
Answer and explanation
Answer: C. An abstract class can have constructors, but an interface cannot
Explanation: An abstract class can define constructors, which run when a subclass object is created. Interfaces cannot have constructors. Java allows only single class inheritance, and abstract classes cannot be instantiated.
Previous: What is the output of the following Java code? · Next: In C++, how is the "diamond problem" (two copies of a common base class…
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
- A Car object contains an Engine object. This "has-a" relationship is best…
- What is the output of the following Java code?
- What is the output of the following Java code?
- In C++, how is the "diamond problem" (two copies of a common base class…
- Which pair of method declarations CANNOT both appear in the same Java class?
- What is printed when new C() is executed?
- What is the output of the following Java code?
- What is the output of the following Java code?
- What is the output of the following Java code?
- Which SOLID principle states that objects of a subclass should be usable…
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