This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instanceOf?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "instanceOf??" Watch "instanceOf??" New topic
Author

instanceOf??

srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
hi frnds,

This is a simple doubt .Here tree is of type Tree and it points to an object of pine .so in the output

tree is an instance of Pine ..that is fine ..
tree is not an instance of Oak ..that is also fine..
tree is of type Tree ...is it right to say that tree is an instance of Tree..

coz in the output i get..
pine
Tree
Oops

thanks

sri


Thanks & Regards<br /> <br />-Srikanth
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
Hi,

Doubt is obvious. Ok Do you belive that every String is an Object Or Do you belive that every Chair or Table is a Furniture...??

If you DO then why, simply because
String extends Object
and ofcourse Chair is a Furniture (we can say Chair extends Furniture)

If we say that String is an object or Chair is a Furniture that means we say that String is an instance of Object or Chair is an instance of Furniture.

Similary every Pine is also instance of Tree
you will get the same result if you try
Pine isntanceof Object.......would'nt you?

Hence every subclass Object is ofcourse an instance of its super class

Hope it helps
[ October 11, 2005: Message edited by: Sandeep Chhabra ]

Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: instanceOf??