0
Why does not work
animal class will be inheited by dog and cat class THIS IS THE CONCEPT when did i need to declare object like this declaration.this is a compilation error rised... Dog a=new Dog(); based on the polyporphism concept example says animal a=new Dog(); correct!!!
3 odpowiedzi
0
I barely understand what you are saying, but I think your example is about interfaces
0
bro....based on polymorphism concept,i have a doubt to declare object....
class animal
class dog extends animal
class cat extends animal
in main
animal a=new Dog();
this is concept for declare object for that....
In this , why they use" animal "word
0
My opinion is this...
The normal way to instantiate class dog would be:
Dog d = new Dog();
But since we know that Dog inherits from Animal, we can upcast an instance of our subclass (Dog) to the superclass (Animal). Hence;
Animal a = new Dog();
I hope that was helpful :-)