File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Casting & Converting using Object Refrence 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 & Converting using Object Refrence" Watch "Casting & Converting using Object Refrence" New topic

Casting & Converting using Object Refrence

suresh kamsa
Ranch Hand

Joined: Jul 30, 2001
Posts: 149
Can any one explain me about object refrence converting and casting using examples classes,interfaces etc.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Why not try to narrow your focus a little. Why not tell us what is confusing you.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
suresh kamsa
Ranch Hand

Joined: Jul 30, 2001
Posts: 149
I read about Casting and converting in RHE book. I understood what they were talking about. But when I was trying to solve some questions from DAN's mock exam I am not able to do anything. I am getting confused at using interfaces when we are doing object refrence.
I understood object refrence in upward hierarchy is possible not in downwards.
class a
class b extends a
b b1 = new b;
a = b1;
It is possible because b is a subclass of a.
When it comes to Interfaces I have know idea.
Thanks for asking me about my confustion part.
zarina mohammad
Ranch Hand

Joined: Jun 26, 2002
Posts: 104
When it comes to interface a class can be cast to interface implicitly if the class implements the interface.
But explicit conversion is needed to cast an interface to class implementing the interface(which is legal even at runtime) or to a class not implementing the interface(illegal at runtime)
this example might help you understand better
I agree. Here's the link:
subject: Casting & Converting using Object Refrence
It's not a secret anymore!