This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inheritance and Polymorphism Involving Interface Casting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inheritance and Polymorphism Involving Interface Casting" Watch "Inheritance and Polymorphism Involving Interface Casting" New topic
Author

Inheritance and Polymorphism Involving Interface Casting

Jae Lim
Greenhorn

Joined: Feb 20, 2009
Posts: 12
Hello Ranchers!
Can someone please explain me how compiler is always happy with interface casting? Please look at the code below.
Any help is appreciated..!

Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
In line 15, _A does not implement interface, but a subclass of it might implement it. Hence it is allowed.

Only when the class is final..compiler is sure it cannot have subclasses..and hence they cannot implement the interface.

In the last line of your code ..Line 28



..if you try to cast c (which is final) instead of a..you can upset the compiler then


SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
Jae Lim
Greenhorn

Joined: Feb 20, 2009
Posts: 12
Thanks for the explanation it makes sense now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inheritance and Polymorphism Involving Interface Casting