Interfaces vs Abstract Classes in Java


Use interfaces when you want to specify that different classes should use a particular method. Use abstract classes for common methods and fields.

Source Code

interface AnimalInterface {
    void animalSound(); // interface method does not have a body
}
abstract class AnimalClass {
    public abstract void animalSound();
    public void sleep() {
        System.out.println("Zzz");
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments