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).]
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??
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).