instanceof operator, without the use of java instanceof

Java Programming Language / Operators in java

1016

Program:


class Parent { }

class Child extends Parent {

  static void method(Parent a) {

       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.