instanceof Operator in Java

instanceof operator is used to test whether an object is an instance of class.

Example 1 : Greeting Cards

instanceof Operator

instanceof Operator

instanceof operator returns true if c is an instance of BirthdayCard class otherwise false. If the result of instanceof operator is true then corresponding cast expression will always be valid. instance of operator .

Example 2 : Fruit

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.