tampurus

38 Use of abstract class in java

May 2nd, 2022 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. abstract class Animal {
  2.   abstract void makeSound();
  3.  
  4.   public void eat() {
  5.     System.out.println("I can eat.");
  6.   }
  7. }
  8.  
  9. class Dog extends Animal {
  10.   public void makeSound() {
  11.     System.out.println("Bark bark");
  12.   }
  13. }
  14.  
  15. class Main {
  16.     public static void main(String[] args) {
  17.         Dog d1 = new Dog();
  18.         // creating obj of dog class
  19.         d1.makeSound();
  20.         d1.eat();
  21.   }
  22. }
  23. // Output
  24. Bark bark
  25. I can eat.
Add Comment
Please, Sign In to add comment