Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal
- {
- public void callme()
- {
- System.out.println("In callme of Animal");
- }
- }
- class Dog extends Animal
- {
- public void callme()
- {
- System.out.println("In callme of Dog");
- }
- public void callme2()
- {
- System.out.println("In callme2 of Dog");
- }
- }
- public class UseAnimlas
- {
- public static void main (String [] args)
- {
- Dog d = new Dog();
- Animal a = (Animal)d;
- d.callme();
- a.callme();
- ((Dog) a).`callme2`();
- }
- }
- Animal animal = new Dog();
- Dog castedDog = (Dog) animal;
- Animal animal = new Animal();
- Dog dog = (Dog) animal;
- Animal a = (Animal)d;
- Animal a = d;
- class Dog extends Animal
- {
- public void callme()
- {
- super.callme();
- System.out.println("In callme of Dog");
- }
- ...
- }
- {
- System.out.println("In callme of Animal");
- }
- public void callme()
- {
- System.out.println("In callme of Dog");
- }
- public void callme2()
- {
- System.out.println("In callme2 of Dog");
- }
- public static void main (String [] args)
- {
- Animal animal = new Animal ();
- Dog dog = new Dog();
- Animal ref;
- ref = animal ;
- ref.callme();
- ref= dog;
- ref.callme();
- //dog.callme2();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement