What is instanceof operator ?
hat is the meaning of instanceof operator ? and Why it is used in OOPS programming ? and How to implement in program ?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Priyanka K SRank #1,385 · 1.2K reputationPosted Dec 27, 2019, 12:08 AM EST
Daril148 reputationPosted Nov 16, 2021, 2:26 AM EST
It is used to test if an object/instance is a subtype of a given type. It is a binary operator and returns a boolean value(true/false)
you can use it to find out if an object is an instance of a class.
class AAA{ public static void main(String args[]){ AAA a=new AAA(); System.out.println(a instanceof AAA); } }The output will be "true".
a subcalss's object is also a type of parent calss. Example if bee extends insects then object of bee can be referred by both the bee or insects calss.