Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 9th, 2010  |  syntax: Java 5  |  size: 0.43 KB  |  views: 1,027  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. public class Main {
  3.         class A { };
  4.         class B extends A { };
  5.         class C extends B { };
  6.        
  7.         private void run() {
  8.                 B b = new C();
  9.                
  10.                 System.out.println(b instanceof A);
  11.                 System.out.println(A.class.isAssignableFrom(b.getClass()));
  12.                 System.out.println(B.class.isAssignableFrom(b.getClass()));
  13.                 System.out.println(C.class.isAssignableFrom(b.getClass()));
  14.         }
  15.  
  16.         public static void main(String[] args) {
  17.                 new Main().run();
  18.         }
  19.  
  20. }