JAVA PROGRAM TO UNDERSTAND SINGLE INHERITANCE
// Understanding Single Inheritance
class Animal {
void eat() {
System.out.println("Animal is eating");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Dog is barking");
}
}
public class Main {
public static void main(String[] args) {
Dog myDog = new Dog();
myDog.eat();
myDog.bark();
}
}
Comments
Post a Comment