Machine-translated by Google. Questions are authored in English.
Top

Discussion

In Java, which keyword prevents a class from being inherited ?

  • A.static
  • B.abstract
  • C.final
  • D.private

Answer: C

A class is protected from inheritance by the keyword final.

A class declared final cannot be extended: any attempt to write class B extends A, where A is final, fails to compile. String and the wrapper classes such as Integer are final for this reason. The same keyword stops a method being overridden or a variable being reassigned.

static marks members that belong to the class rather than to objects. abstract means the opposite of final: an abstract class exists to be inherited. A top-level class cannot be private in Java.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.