public class abc{ int i= 34; void check(){ System.out.println("Inside the parent method"); } } class def extends abc{ int i = 44; void check(){ System.out.println("Inside the child method"); } public static void main(String args[]){ abc a = new abc(); def d = new def(); a = d; System.out.println(a.i); a.check(); } }
"This code compiles fine but giving runtime error. Can anybody explain me.
deekasha gunwant
Ranch Hand
Joined: May 06, 2000
Posts: 396
posted
0
Hi Shailender, The code is perfect and does run on my m/c. The mistake u seem to be doing is that instead of running the class def i.e. java def u may be using java abc which may be resulting in main :nosuchmethoderror in class abc.error at runtime. so don't forget that u can run only that class which has got the main method correctly defined. hope i guessed your problem right. regards deekasha
Doit
Ranch Hand
Joined: Aug 03, 2000
Posts: 169
posted
0
Deekasha, Can u help me understand object reference casting? I read in RHE but still confused. I think u could help me. - Thanks
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Originally posted by deekasha gunwant: Thanx, Deekasha, u r right, The problem was with file name only. Now it is working fine. Thanx once again. --Shallender