Java Single Inheritance Example

In single inheritance, subclasses inherit the features of one superclass. 

Java Single Inheritance Example

class Animal {
    void eat() {
        System.out.println("eating...");
    }
}
class Dog extends Animal {
    void bark() {
        System.out.println("barking...");
    }
}
class TestInheritance {
    public static void main(String args[]) {
        Dog d = new Dog();
        d.bark();
        d.eat();
    }
}
Output
barking...
eating...

Comments