Tuesday, 3 November 2015

Java Tutorial : Java instanceOf Operator

Click here to watch in Youtube :

Click the below Image to Enlarge
Java Tutorial : Java instanceOf Operator 

public interface Employee

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;

public class Child extends Parent
    private String schoolName;

    public String getSchoolName()
        return schoolName;

    public void setSchoolName(String schoolName)
        this.schoolName = schoolName;

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("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));


parentObject instanceof Parent: true
parentObject instanceof Child: false
parentObject instanceof Employee Interface: true

childObject instanceof Parent: true
childObject instanceof Child: true
childObject instanceof Employee Interface: true
Click the below link to download the code:

Github Link:

Bitbucket Link:/span>

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge