fork download
  1. class Tree {
  2. void print () {System.out.println("Tree");}
  3.  
  4. public static void main(String args[]) {
  5. Tree[] a = new Tree[3];
  6. a[0] = new Tree();
  7. a[1] = new Banyan();
  8. a[2] = new Peepal();
  9. for (int i=0; i<a.length; i++) {
  10. ((Tree)a[i]).print();
  11. }
  12. }
  13.  
  14. };
  15.  
  16. class Banyan extends Tree {
  17. void print () {System.out.println("Banyan");}
  18. };
  19.  
  20. class Peepal extends Tree {
  21. void print () {System.out.println("Peepal");}
  22. };
Success #stdin #stdout 0.08s 51016KB
stdin
Standard input is empty
stdout
Tree
Banyan
Peepal