• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question on instanceof operator..

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
source:www.jchq.net


Which of the following statements are true?

1)The instanceof operator can be used to determine if a reference is an instance of a class,but not an interface.
2)The instanceof operator can be used to determine if a reference is an instance of a particular wrapper class.
3)The instanceof operator wil;l only determine if a reference is an instance of a class immediately above in the hierarchy but no further up the inheritance chain.
4)the instanceof operator can be used to determine if one reference is of the same class as another reference thus..

can anyone answer this with explanation?
 
Author
Posts: 3473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try some examples and see if you could figure this out. If you do that you will remeber this better for example try the option 2 as




Integer is a wrapper class. Here is another hint

You use the instanceof operator to test if an object is a subclass of a specific class or implements a specific interface.



Also, try the other options via code.
reply
    Bookmark Topic Watch Topic
  • New Topic