Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a Java Program To Explain The Concept of Various Inheritance
- //3. Hierarchical Inheritance
- class Animal
- {
- void eat()
- {
- System.out.println("Eating");
- }
- }
- class Dog extends Animal
- {
- void bark()
- {
- System.out.println("Barking");
- }
- }
- class Cat extends Animal
- {
- void cry()
- {
- System.out.println("Cat is Crying");
- }
- }
- class Ex15 // Ex15 is FileName
- {
- public static void main(String args[])
- {
- Cat c = new Cat();
- c.eat();
- c.cry();
- Dog d = new Dog();
- d.eat();
- d.bark();
- }
- }
Add Comment
Please, Sign In to add comment