22.10 Interfaces and Abstract Classes
Interfaces and Abstract Classes
Overview
Interfaces and abstract classes define methods that must be implemented by subclasses.
Topics
- Defining Interfaces
- Implementing Interfaces
- Abstract Classes
- Differences Between Interfaces and Abstract Classes
Examples
interface Animal {
void sound();
}
class Dog implements Animal {
public void sound() {
System.out.println("Dog barks");
}
}
abstract class Vehicle {
abstract void start();
}
class Car extends Vehicle {
void start() {
System.out.println("Car starts");
}
}