instanceof operator, Nice example

Java Programming Language / Operators in java

955

Program:

interface Animal{}
class Mammal implements Animal{}

public class Cat extends Mammal {

   public static void main(String args[]) {
      Mammal m = new Mammal();
      Cat d = new Cat();

      System.out.println(m instanceof Animal);
      System.out.println(d instanceof Mammal);
      System.out.println(d instanceof Animal);
   }
}

Output:

true
true
true
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.