In Java, 'extends' is valid only when both X and Y are classes, or when both X and Y are interfaces. A class cannot extend an interface (it implements it), and an interface cannot extend a class. This rule maintains the type system's consistency - inheritance relationships must be between the same kind of type.