Java SE 11 Developer — Question 4

Given:
public class X {
}
and
public final class Y extends X {
}
What is the result of compiling these two classes?

Answer options

Correct answer: B

Explanation

The correct answer is B because in Java, every class must either directly or indirectly implement the toString() method if it is extended, which is not done here. Option A is incorrect because Java provides a default no-argument constructor for classes that do not define any constructor. Option C is wrong as a final class can extend another class; it just cannot be subclassed itself. Option D is false because the compilation does not succeed due to the missing toString() method implementation.