instanceof operator, downcasting with instanceof

Java Programming Language Operators in java (Article) Operators in java (Program)

28571

Program:

 class Parent { }

class Child extends Parent {

  static void method(Parent a) {
    if(a instanceof Child){
       Child d=(Child)a;//downcasting
       System.out.println("ok downcasting performed");
    }
  }

  public static void main (String [] args) {
    Parent a=new Child();
    Child.method(a);
  }
}

Output:

ok downcasting performed
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.