Explain the outputs (or error) for the following test program.
public class TestAnimal {
public static void main (String [ ] args) {
// Using the subclasses
Cat cat1 = new Cat ();
cat1.greeting () ;
Dog dogl= new Dog();
dogl.greeting () ;
Bigoog bigDogl new Bigbog () ;
bigoog1.greeting () ;
// Using Polymorphism
Animal animal1 = new Cat ();
animal1.greeting () ;
Animal animal2 = new Dog();
animal2.greeting () ;
Animal animal3 new Bigbog () ;
animal3.greeting () ;
Animal animal4 =new Animal ();
//Downcast
Dog dog2= (Dog) animal2;
Bigbog bigDog2= (Bigoog) animal3;
Dog dog3 = (Dog) animal3;
Cat cat2 = (Cat) animal2;
dog2.greeting (dog3) ;
dog3.greeting (dog2) ;
dog2.greeting (bigDog2);
bigDog2.greeting (dog2);
bigbog2.greet ing (bigDog1);
}
}
Answers
Answered by
0
Answer:
what is this
pls give the question
Similar questions
Math,
2 months ago
Accountancy,
5 months ago
Math,
5 months ago
Math,
11 months ago
Math,
11 months ago