This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Question regarding Interface with instanceof operator Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 19216

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
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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Question regarding Interface with instanceof operator
 
Similar Threads
Question on "instanceof"
A cast problem!!
instanceof operator for superclass
Multiple Interfaces
instanceof Operator Question - K&B Book-Chapter 4 self-test section