OCA Java SE 8 Class Design - OCA Mock Question Class Design 15








Question

Which statements are true for both abstract classes and interfaces? (Choose all that apply)

  1. All methods within abstract classes and interfaces are assumed to be abstract.
  2. abstract classes and interfaces can contain public static final variables.
  3. abstract classes and interfaces can be extended using the extend keyword.
  4. abstract classes and interfaces can contain default methods.
  5. abstract classes and interfaces can contain static methods.
  6. abstract classes and interfaces cannot be instantiated directly.
  7. abstract classes and interfaces inherit java.lang.Object.




Answer



B, C, E, F.

Note

A is wrong, because an abstract class may contain concrete methods.

Since Java 8, interfaces may also contain concrete methods in form of static or default methods.

Although all variables in interfaces are assumed to be public static final, abstract classes may contain them as well, so B is correct.

Both abstract classes and interfaces can be extended with the extends keyword, so C is correct.

Only interfaces can contain default methods, so D is incorrect.

Both abstract classes and interfaces can contain static methods, so E is correct.

Both abstract classes and interfaces require a concrete subclass to be instantiated, so F is correct.

An interface itself doesn't inherit java.lang.Object. G is incorrect.