ProgrammingHardProduct-company placement · GATE CS

How many of these statements about Java (9 or later) are correct? 1. An interface can declare instance fields. 2. An abstract class can have a constructor. 3. An interface can have private methods. 4. A class can extend two abstract classes. 5. An interface method with a body must be default, static or private.

  1. A. 2
  2. B. 3
  3. C. 4
  4. D. 1

Correct answer: B. 3

2, 3 and 5 are true: abstract-class constructors run when subclasses are built, and Java 9 added private interface methods. Interface fields are implicitly public static final, so 1 is false, and Java has only single class inheritance, so 4 is false.

More OOP with C++ and Java questions

Exams that ask this topic