File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Casting Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Casting Object" Watch "Casting Object" New topic
Author

Casting Object

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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
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
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Casting Object