Virajsinh

Java_15

Feb 15th, 2018
55
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Write a Java Program To Explain The Concept of Various Inheritance
  2. //3. Hierarchical Inheritance
  3.  
  4. class Animal
  5. {
  6.     void eat()
  7.     {
  8.         System.out.println("Eating");
  9.     }
  10. }
  11.  
  12. class Dog extends Animal
  13. {
  14.     void bark()
  15.     {
  16.         System.out.println("Barking");
  17.     }
  18. }
  19.  
  20. class Cat extends Animal
  21. {
  22.     void cry()
  23.     {
  24.         System.out.println("Cat is Crying");
  25.     }
  26.    
  27. }
  28.  
  29. class Ex15 // Ex15 is FileName
  30. {
  31.     public static void main(String args[])
  32.     {
  33.         Cat c = new Cat();
  34.         c.eat();
  35.         c.cry();
  36.        
  37.         Dog d = new Dog();
  38.         d.eat();
  39.         d.bark();
  40.     }
  41. }
RAW Paste Data