Final Class

Final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.

  • A final class may be instantiated.
  • A class with a final function may be derived.
  • Static functions can be final.
  • Preventing massive inheritance chain of doom
  • Encouraging composition
  • Force the developer to think about user public API
  • Force the developer to shrink an object’s public API
  • A final class can always be made extensible
  • extends breaks encapsulation
  • You don’t need that flexibility
  • You are free to change the code

Leave a Reply

Your email address will not be published. Required fields are marked *