Polymorphism question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Polymorphism question

did i understand polymorphism correctly? if i use pokemon as reference(Pokemon p1=new Pikachu(); & Pokemon p2=new charmander();),i can access any pikachu&charmander methods only if the subclasses contain the same method as pokemon class. if i use pikachu as reference ( Pikachu p1=new Pikachu();) i can access all pikachu and pokemon's methods but not charmander's methods https://code.sololearn.com/c0I7Zo8qSeoT/?ref=app

22nd Nov 2017, 3:34 AM
oyl
2 Answers
+ 3
yes that is pretty much it however parent class can only access methods which you have overridden eg Pokemon p4=new Pikachu(); p4.attack(); This will show an error
22nd Nov 2017, 4:04 AM
Peerzada Burhan
Peerzada Burhan - avatar
0
While some of the words you use aren't what I would use, I believe you understand the concept.
22nd Nov 2017, 3:58 AM
John Wells
John Wells - avatar