An abstract class in Java is a class that cannot be instantiated and is used as a blueprint for other classes. It can include both abstract methods (without implementation) and concrete methods (with implementation).
Key Features:
1. Abstract Methods: Declared without a body; subclasses must override them.
2. Concrete Methods: Can be defined within the abstract class and inherited by subclasses.
3. Inheritance: Serves as a base class for subclasses, promoting code reusability and design flexibility.
Example:
abstract class Animal {
abstract void sound();
void eat() {
System.out.println(“This animal eats food”);
}
}
class Dog extends Animal {
void sound() {
System.out.println(“Bark”);
}
}
In this example, Animal is an abstract class with an abstract method sound() and a concrete method eat(). The Dog class extends Animal and provides an implementation for the sound() method.