Which is true? (Choose all that apply. )
-
"X extends Y" is correct if and only if X is a class and Y is an interface.
-
"X extends Y" is correct if and only if X is an interface and Y is a class.
-
"X extends Y" is correct if X and Y are either both classes or both interfaces.
-
"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
In Java, the 'extends' keyword is used for class-to-class inheritance and interface-to-interface inheritance. A class extends another class, and an interface extends another interface. When a class implements an interface, we use 'implements', not 'extends'. Options A and B are incorrect because they mix classes and interfaces with 'extends'. Option D is incorrect because 'extends' cannot work across class-interface boundaries.
In Java, the extends keyword works within a like kind: a class may extend at most one other class (single inheritance), and an interface may extend one or more other interfaces (multiple inheritance of type). A class can never extend an interface, and an interface can never extend a class — those relationships use 'implements' instead, or don't exist. So 'X extends Y' is syntactically legal precisely when X and Y are both classes, or both interfaces (subject to no circular inheritance). Options A and B get the class/interface roles backwards (extends never crosses class↔interface). Option D is wrong because a class extending another class is limited to one parent — you can't have every combination (e.g., a class can't extend multiple classes) — so 'all combinations' overstates it.