aspose file tools*
The moose likes Beginning Java and the fly likes Question regarding Interface with instanceof operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question regarding Interface with instanceof operator" Watch "Question regarding Interface with instanceof operator" New topic
Author

Question regarding Interface with instanceof operator

ashwin bhawsar
Ranch Hand

Joined: Mar 16, 2011
Posts: 62

Nico Van Brandt
Ranch Hand

Joined: Mar 31, 2011
Posts: 66

instanceof checks for an 'IS-A' relationship. For that reason, because SpeedBoat is a Toy, it returns true.


Oracle Java SE6 Certified Programmer
Oracle Java EE5 Certified Web Component Developer
Karim Hamamouch
Greenhorn

Joined: Jun 07, 2011
Posts: 5

I'd add that parent classes and interfaces are part of the inheritance tree of a class therefore the 'IS-A' principle is applied, as said previously'.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19794
    
  20

Even though at that time b is a SpeedBoat and therefore a Toy, the reference is used to determine which methods can be called, and the reference is one to Boat, not Toy or SpeedBoat. The compiler doesn't look at the actual value of the reference.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
ashwin bhawsar
Ranch Hand

Joined: Mar 16, 2011
Posts: 62

Thanks for all your replies
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question regarding Interface with instanceof operator