| 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
|
 |
 |
|
|
subject: Question regarding Interface with instanceof operator
|
|
|