Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. class Animal
  2. {
  3. public void callme()
  4. {
  5. System.out.println("In callme of Animal");
  6. }
  7. }
  8.  
  9.  
  10. class Dog extends Animal
  11. {
  12. public void callme()
  13. {
  14. System.out.println("In callme of Dog");
  15. }
  16.  
  17. public void callme2()
  18. {
  19. System.out.println("In callme2 of Dog");
  20. }
  21. }
  22.  
  23. public class UseAnimlas
  24. {
  25. public static void main (String [] args)
  26. {
  27. Dog d = new Dog();
  28. Animal a = (Animal)d;
  29. d.callme();
  30. a.callme();
  31. ((Dog) a).`callme2`();
  32. }
  33. }
  34.  
  35. Animal animal = new Dog();
  36. Dog castedDog = (Dog) animal;
  37.  
  38. Animal animal = new Animal();
  39. Dog dog = (Dog) animal;
  40.  
  41. Animal a = (Animal)d;
  42.  
  43. Animal a = d;
  44.  
  45. class Dog extends Animal
  46. {
  47. public void callme()
  48. {
  49. super.callme();
  50. System.out.println("In callme of Dog");
  51. }
  52. ...
  53. }
  54.  
  55. {
  56.  
  57. System.out.println("In callme of Animal");
  58.  
  59. }
  60.  
  61. public void callme()
  62.  
  63. {
  64.  
  65. System.out.println("In callme of Dog");
  66.  
  67. }
  68.  
  69. public void callme2()
  70.  
  71. {
  72.  
  73. System.out.println("In callme2 of Dog");
  74.  
  75. }
  76.  
  77. public static void main (String [] args)
  78.  
  79. {
  80.  
  81. Animal animal = new Animal ();
  82.  
  83. Dog dog = new Dog();
  84.  
  85. Animal ref;
  86.  
  87. ref = animal ;
  88.  
  89. ref.callme();
  90.  
  91. ref= dog;
  92.  
  93. ref.callme();
  94.  
  95. //dog.callme2();
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement