Abstract Classes and Methods in Java


Abstract classes and methods are when you want to define a template for other classes.

Source Code

abstract class Animal {
    public abstract void animalSound();
    public void sleep() {
        System.out.println("Zzz");
    }
}
class Pig extends Animal {
    public void animalSound() {
        System.out.println("The pig says: wee wee");
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments