View RSS Feed

Java Object

The instanceof Keyword

Rate this Entry
by , 04-26-2012 at 05:33 PM (987 Views)
Instanceof operator can be used for determining that dog is an animal & Mammal is an animal.
interface Animal{}
Java Code:
class Mammal implements Animal{}

class Dog extends Mammal{
   public static void main(String args[]){

      Mammal m = new Mammal();
      Dog d = new Dog();

      System.out.println(m instanceof Animal);
      System.out.println(d instanceof Mammal);
      System.out.println(d instanceof Animal);
   }
}
Following result will be produced:

true
true
true

Submit "The instanceof Keyword" to Facebook Submit "The instanceof Keyword" to Digg Submit "The instanceof Keyword" to del.icio.us Submit "The instanceof Keyword" to StumbleUpon Submit "The instanceof Keyword" to Google

Comments