ProgrammingHardGATE CS · TCS NQT Prime · Product Company SDE
Which statement correctly distinguishes an abstract class from an interface in Java (interfaces may have default/static/private methods since Java 8/9)?
- A. An abstract class can declare constructors and hold instance fields with real per-object state; a plain interface cannot hold mutable instance state
- B. An interface can declare constructors but an abstract class cannot
- C. Abstract classes can never contain a concrete (non-abstract) method
- D. A class may extend any number of abstract classes but only implement one interface
Correct answer: A. An abstract class can declare constructors and hold instance fields with real per-object state; a plain interface cannot hold mutable instance state
Abstract classes behave like ordinary classes (constructors, instance fields, partial implementation); interfaces only expose constants (implicitly public static final fields), never per-instance mutable state.
More OOP with C++ and Java questions
- Within a single derived class's own constructor body, in what order are its direct base class subobjects (assuming no virtual inheritance)…
- Which statement correctly describes the typical cost of exceptions in C++?
- Why can a generic method not simply write new T[10] for a type parameter T in Java?
- java void f(int x) { System.out.print("int"); } void f(Integer x) { System.out.print("Integer"); } void f(Object... x) {…
- Why does adding a brand-new virtual function to a base class not increase the size of each object in that hierarchy (assuming objects…
- Which java.util.function functional interface best fits a lambda that takes one argument of type T and returns a boolean?