Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Casting & Converting using Object Refrence

 
suresh kamsa
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one explain me about object refrence converting and casting using examples classes,interfaces etc.
Thanks.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not try to narrow your focus a little. Why not tell us what is confusing you.
 
suresh kamsa
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Ex
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
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic