Skip to main content
An abstract class in Kotlin is a restricted class declared with the abstract keyword that cannot be instantiated directly. It serves as a structural template for subclasses, allowing the definition of both concrete members (with state and implementation) and abstract members (without implementation) that derived classes must resolve.

Core Technical Characteristics

  • Instantiation: Attempting to instantiate an abstract class directly results in a compilation error. It must be subclassed.
  • Implicitly Open: Abstract classes are implicitly open for extension. Applying the open modifier to the class itself is redundant.
  • Abstract Members: Properties and functions declared with the abstract keyword do not have an implementation or initial state. They are implicitly open and mandate an override in any concrete subclass.
  • Concrete Members: Functions and properties without the abstract modifier behave as they do in standard classes. They are implicitly final (cannot be overridden unless explicitly marked open) and can maintain state or provide default implementations.
  • Constructors: Abstract classes can define primary and secondary constructors, as well as init blocks. Subclasses are required to invoke the superclass constructor.

Syntax Visualization

Advanced Mechanics

Overriding Open Members with Abstract An intermediate abstract class can override an open member from its superclass and declare it abstract. This forces all subsequent concrete subclasses down the hierarchy to provide a new implementation, effectively stripping the default implementation provided by the original superclass.
Property Initialization Rules Abstract properties cannot be initialized or possess custom getters/setters within the abstract class. They strictly define the contract (name and type). If an abstract property is declared as a val, a subclass can override it as a var. However, an abstract var cannot be overridden as a val.
Tired of Poor Kotlin Skills? Fix That With Deep Grasping!Learn More