Java OCA OCP Practice Question 1852

Question

Which one of these is a proper definition of a class Main that cannot be sub-classed?

Select 1 option

  • A. class Main { }
  • B. abstract class Main { }
  • C. native class Main { }
  • D. static class Main { }
  • E. final class Main { }


Correct Option is  : E

Note

A class can be extended unless it is declared final.

While declaring a method, static usually implies that it is also final, this is not true for classes.

An inner class can be declared static and still be extended.

For classes, final means it cannot be extended.

For methods, final means it cannot be overridden in a subclass.

The native keyword can only be used on methods, not on classes and instance variables.




PreviousNext

Related