• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

instance of operator

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello friends ,
please can anybody tell me the significance of instanceof operator and how is it works ?
thanks in advance
Rahul
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rahul Pawar:
hello friends ,
please can anybody tell me the significance of instanceof operator and how is it works ?
thanks in advance
Rahul


The instanceof operator can be used to test if an object
�belongs to� a particular class type, inherits from a class,
or whether it implements an interface.
Suppose JButton b=new JButton();
if(b instanceOf JComponent)
//returns true as b's class JButton is a sub-class of JComponent
if(b instanceOf JButton)
//returns true as b's class is JButton
if(b instanceOf JCheckBox)
//returns false as b's class is not JCheckBox or JButton is not a sub-class of JCheckBox
Suppose a class Example implements the interface Serializable
Example ex=new Example();
if(ex instanceOf Serializable)
//returns true as the object's (ex's) class Example implements Serializable interface
[This message has been edited by sai challa (edited April 18, 2001).]
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also checkout Section 15.20.2 Type Comparison Operator instanceof of the Java Language Specification document.
 
Rahul Pawar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for ur reply
but will u please give me how instanceof operator works with the arrays .
thanks in advance
Rahul
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I urge you to write a small program to see for yourself!! Experience is the best teacher. It is not hard for someone to answer your question, but I do think you have enough knowledge to start playing with it. Dont you??
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic