Abstract classes, final classes and methods

Filter Course


Abstract classes, final classes and methods

Published by: Dikshya

Published date: 27 Jun 2023

Abstract Classes, Final Classes and Methods

Abstract Classes:

      Abstract classes are classes that cannot be instantiated directly. They serve as a blueprint for other classes and are designed to be subclassed.

      An abstract class can have both abstract and non-abstract methods. Abstract methods are declared without an implementation and must be implemented by any concrete (non-abstract) subclass. Abstract classes can also have concrete methods with an implementation that can be inherited by the subclasses. Subclasses of an abstract class must either implement all the abstract methods or be declared as abstract themselves.

Final Classes:

Final classes are classes that cannot be subclassed. Once a class is declared as final, it cannot be extended by any other class. This is useful when you want to prevent any further modification or extension of a class.

     Final classes are often used to provide immutable or utility classes that should not be overridden or inherited from.

Final Methods:

   Final methods are methods that cannot be overridden by subclasses. When a method is declared as final in a class, it means that the method implementation in the class cannot be changed in any subclass. This is useful when you want to ensure that the behavior of a particular method remains constant across all subclasses.

  Final methods are commonly used when you have a critical implementation that should not be modified or overridden by subclasses.

In summary, abstract classes are used as a blueprint for other classes, with abstract methods that must be implemented by subclasses. Final classes cannot be subclassed, and final methods cannot be overridden by subclasses. Both abstract and final concepts are used to control class and method inheritance and provide specific behavior restrictions.