09 Abstraction
09 Abstraction
} }
}
▪ Common Blueprint: Abstract classes provide a common blueprint for all derived
classes. They force the derived classes to implement certain methods, ensuring a
consistent interface.
▪ Code Reusability: By using abstract classes, you can reuse common code (like the
Sleep() method in the Animal example) while allowing derived classes to provide
their specific implementation for abstract methods.
▪ Polymorphism: Abstract classes are often used with polymorphism, allowing you to
treat objects of different derived classes as objects of the base class.
▪ An abstract class cannot be instantiated directly. You can only create objects of its
derived classes.
▪ If a class contains even one abstract method, it must be declared as an abstract
class.
▪ Derived classes must implement all abstract methods of the abstract class unless
the derived class is also abstract.
▪ Abstract classes can have both abstract and regular (non-abstract) methods.