Java OCA OCP Practice Question 1708

Question

Which one of the following class declarations is a valid declaration of a class that cannot be extended?.

Select the one correct answer.

  • (a) class Main { }
  • (b) abstract class Main { }
  • (c) native class Main { }
  • (d) static class Main { }
  • (e) final class Main { }
  • (f) private class Main { }
  • (g) abstract final class Main { }


(e)

Note

A class can be extended unless it is declared final.

For classes, final means it cannot be extended, while for methods, final means it cannot be overridden in a sub-class.

A nested static class, (d), can be extended.

A private member class, (f), can also be extended.

The keyword native can only be used for methods, not for classes and fields.




PreviousNext

Related