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!!!

1st Jan 2017, 6:30 PM
Sundar vinayak
Sundar vinayak - avatar
3 odpowiedzi
0
I barely understand what you are saying, but I think your example is about interfaces
1st Jan 2017, 6:55 PM
Dago VF
Dago VF - avatar
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
1st Jan 2017, 7:03 PM
Sundar vinayak
Sundar vinayak - avatar
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 :-)
12th Jan 2017, 7:24 AM
Jacob Makau
Jacob Makau - avatar