Which one of the following class definitions is a valid definition of a class that cannot be extended?

  1. abstract class Link { }

  2. native class Link { }

  3. final class Link { }

  4. abstract final class Link { }


Correct Option: C

AI Explanation

To answer this question, you need to understand the concept of class modifiers in Java.

Option A) abstract class Link { } - This option is incorrect because an abstract class can be extended by other classes.

Option B) native class Link { } - This option is incorrect because the "native" keyword is used to indicate that a method is implemented in a language other than Java, and it is not used to define a class that cannot be extended.

Option C) final class Link { } - This option is correct because the "final" keyword is used to indicate that a class cannot be extended. Therefore, this class cannot have any subclasses.

Option D) abstract final class Link { } - This option is incorrect because the "abstract" and "final" keywords are contradictory. An abstract class is meant to be extended, while a final class cannot be extended. It is not possible to have a class that is both abstract and final.

The correct answer is C) final class Link { }. This option is correct because the "final" keyword ensures that the class cannot be extended.

Find more quizzes: