Write a program in java to demonstrate instanceof operator?

Instanceof True

class Instance

{

                public static void main(String arg[])

                {

                                Instance x=new Instance();

                                System.out.println(x instanceof Instance);

                }

}

Instanceof True.PNG
Instanceof False

class Instance

{

                public static void main(String arg[])

                {

                                Instance x=null;

                                System.out.println(x instanceof Instance);

                }

}

Instanceof False.PNG
, , , , , , , ,

Leave a Reply