instanceof means what the word means, it returns true or false if the insance is a instance of the given class or not. This means if e.getSource() is an insance of the class JButton the insanceof returns true. insanceof is used to ask an object if it is an instance of a class if you don't no the class of this object.
> instanceof means what the word means, it returns true
> or false if the insance is a instance of the given
> class or not. This means if e.getSource() is an
> insance of the class JButton the insanceof returns
> true. insanceof is used to ask an object if it is an
> instance of a class if you don't no the class of this
> object.
Very good definition
To add, it also checks whether the instance is of JButton or the sub classes of JButton.
Thanks,
ananth
> instanceof means what the word means, it returns true
> or false if the insance is a instance of the given
> class or not. This means if e.getSource() is an
> insance of the class JButton the insanceof returns
> true. insanceof is used to ask an object if it is an
> instance of a class if you don't no the class of this
> object.
> To add, it also checks whether the instance is of
> JButton or the sub classes of JButton.
More precisely, "<relex> instanceof <typeref>" is true if the "(<typeref>) relex" casting works. It works if the <relex> has the type <typeref> itself, or <relex> has the type of a direct of indirect subclass of <typeref>, or if the class which is the type of <relex>, implements the interface <typeref> (directly, of due to the inheritance).
That is, true if the left expression (which is an expression) could be cast to the class/interface shown on the right.
But don't forget, if it is obvious during compiling that it cannot be true, then a compile time error occurs.