Java help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Java help

Classcastexception??? why do i get Classcastexception error for this?could someone explain please... https://code.sololearn.com/cWnu3boE0x0T/?ref=app

27th Oct 2017, 2:54 AM
oyl
1 Answer
+ 3
CHANGE: Pokemon p1=new Pokemon(); ((Pikachu)p1).sound(); TO: Pokemon p1 = new Pokemon(); p1.sound(); ^p1 is already of the Pokemon class type, so you don't need to cast it. That'll fix your problem.
27th Oct 2017, 3:28 AM
AgentSmith