Tuesday, 3 November 2015

Java Tutorial : Java instanceOf Operator


Click here to watch in Youtube :
https://www.youtube.com/watch?v=ykKLRR7aBx0&list=UUhwKlOVR041tngjerWxVccw

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

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


    }

}
Output
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:
https://sites.google.com/site/javaee4321/java/OperatorsDemoInstanceOfApp.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/OperatorsDemoInstanceOfApp

Bitbucket Link:/span>
https://bitbucket.org/ramram43210/java/src/445777649bb0659322badeabdb5f7ba017537917/BasicJava/OperatorsDemoInstanceOfApp/?at=master


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