Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. public class polymor {
  2. // consider this as animal
  3. static class animal {
  4.  
  5. public void sound() {
  6. System.out.println("Animal makes sound");
  7. }
  8. }
  9.  
  10. static class cat extends animal {
  11.  
  12. public void sound() {
  13. System.out.println("meow meow");
  14. }
  15. }
  16.  
  17. static class dog extends animal {
  18.  
  19. public void sound() {
  20. System.out.println("woof woof");
  21. }
  22. }
  23.  
  24. static class owl extends animal {
  25.  
  26. public void sound() {
  27. System.out.println("hoot hoot");
  28. }
  29. }
  30.  
  31. public static void main(String[] args) {
  32. polymor owl1 = new owl();
  33. cat eevee = new cat();
  34. owl1.sound();
  35. eevee.sound();
  36.  
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement