Skip to content

Final


layout: default title: final Classe


We can use the keyword final on a class so that other classes will not be able to extend it.

public final class FinalClass {
  //...
}
public class FinalSubclass extends FinalClass {  // ERROR, does not compile
  //...
}

Practice Exercise

The visibility modifier and final can also be in the order final public. This compiles successfully.

final public class FinalPublicClass {
  //...
}


Drill

Inheritance/com.example.inheritance.drills * Create a class TestClass. It does not need a main method. * Try to make TestClass extend System by adding extends System. * Try to make TestClass extend String. * Try to make TestClass extend StringBuilder. * Try to make TestClass extend Integer. * It didn't work. Make TestClass extend Object.


Prev -- Up -- Next