fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. final Parent[] arr = new Parent[] { new Child1(), new Child2() };
  13.  
  14. for (Parent p : arr) {
  15. if (p instanceof Child1) {
  16. final Child1 child1 = (Child1) p;
  17.  
  18. } else if (p instanceof Child2) {
  19. final Child2 child1 = (Child2) p;
  20.  
  21. }
  22. }
  23. // your code goes here
  24. }
  25.  
  26. private static class Parent {
  27. }
  28.  
  29. private static class Child1 extends Parent {
  30.  
  31. }
  32.  
  33. private static class Child2 extends Parent {
  34.  
  35. }
  36.  
  37.  
  38. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
Standard output is empty