Get class from Object - Java Reflection

Java examples for Reflection:Object

Description

Get class from Object

Demo Code


class Test {//from  ww w .  j av a  2 s.  com
  public static void main(String[] args) {
    A objA = new A();
    B objB = new B();
    System.out.println((objA.getClass() == objB.getClass()));
    System.out.println(objB instanceof A);

    System.out.println((objA.getClass() == objB.getClass()));
    System.out.println(objA instanceof B);
  }
}

class A {

}

class B extends A {

}

Related Tutorials