Multiple choice technology programming languages

Which is true?

  1. "X extends Y" is correct if and only if X is a class and Y is an interface

  2. "X extends Y" is correct if and only if X is an interface and Y is a class

  3. "X extends Y" is correct if X and Y are either both classes or both interfaces

  4. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In Java, the 'extends' keyword can only be used when both X and Y are classes (class inheritance), or when both X and Y are interfaces (interface inheritance). A class extends another class, and an interface extends another interface. A class implements an interface, not extends it.