/* Understanding the concept of instance_of_operator */
package instanceof_operator;
class Parent
{
}
class Child extends Parent
{
}
class MainClass
{
public static void main(String [] args)
{
Parent p=new Parent();
Child c=new Child();
System.out.println(p instanceof Parent);
System.out.println(c instanceof Child);
System.out.println(c instanceof Parent);
System.out.println(p instanceof Child);
p=c;
System.out.println(c instanceof Child);
System.out.println(p instanceof Parent);
System.out.println(c instanceof Parent);
System.out.println(p instanceof Child);
}
}
output
true
true
true
false
true
true
true
true
package instanceof_operator;
class Parent
{
}
class Child extends Parent
{
}
class MainClass
{
public static void main(String [] args)
{
Parent p=new Parent();
Child c=new Child();
System.out.println(p instanceof Parent);
System.out.println(c instanceof Child);
System.out.println(c instanceof Parent);
System.out.println(p instanceof Child);
p=c;
System.out.println(c instanceof Child);
System.out.println(p instanceof Parent);
System.out.println(c instanceof Parent);
System.out.println(p instanceof Child);
}
}
output
true
true
true
false
true
true
true
true
No comments:
Post a Comment