Employee.java public interface Employee
{
}
Parent.java public class Parent implements Employee
{
private String name;
private String age;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getAge()
{
return age;
}
public void setAge(String age)
{
this.age = age;
}
}
Child.java public class Child extends Parent
{
private String schoolName;
public String getSchoolName()
{
return schoolName;
}
public void setSchoolName(String schoolName)
{
this.schoolName = schoolName;
}
}
InstanceOfOperatorDemo.java class InstanceOfOperatorDemo
{
public static void main(String[] args)
{
Parent parentObject = new Parent();
Parent childObject = new Child();
System.out.println("parentObject instanceof Parent: "
+ (parentObject instanceof Parent));
System.out.println("parentObject instanceof Child: "
+ (parentObject instanceof Child));
System.out.println("parentObject instanceof Employee Interface: "
+ (parentObject instanceof Employee));
System.out.println();
System.out.println("childObject instanceof Parent: "
+ (childObject instanceof Parent));
System.out.println("childObject instanceof Child: "
+ (childObject instanceof Child));
System.out.println("childObject instanceof Employee Interface: "
+ (childObject instanceof Employee));
}
}