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.
- A. 2
- B. 3
- C. 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
- A UI component registers itself as an observer of a long-lived global EventBus when it is created but never unregisters. Screens using…
- A vending machine object behaves differently when Idle, HasCoin or Dispensing, and each state object decides which state comes next. A…
- Account.withdraw(amount) works for any amount up to the balance. A subclass FixedDeposit overrides it to throw an exception unless the…
- Which call violates the Law of Demeter (talk only to your immediate collaborators) inside an OrderService method that receives an Order…
- How many of these statements about Java methods are correct? 1. A final method can be overloaded in a subclass. 2. A static method can be…
- Classes A, B extends A and C extends B all override m(). Inside C, which way can call A's version of m() on the current object?