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. class Veiculo{}
  11.  
  12. class Carro extends Veiculo{
  13. void abriPortaMala(){ System.out.println("Abrindo porta malas");}
  14. }
  15.  
  16. class Onibus extends Veiculo{
  17. void abrirPortaLateral(){System.out.println("Abrindo porta lateral");}
  18. }
  19.  
  20. ArrayList<Veiculo> veiculos = new ArrayList<Veiculo>();
  21.  
  22. void teste(){
  23. veiculos.add(new Carro());
  24. veiculos.add(new Onibus());
  25.  
  26. Carro car = (Carro) veiculos.get(0);
  27. car.abriPortaMala();
  28.  
  29. Onibus bus = (Onibus) veiculos.get(1);
  30. bus.abrirPortaLateral();
  31. }
  32.  
  33. public static void main (String[] args) throws java.lang.Exception
  34. {
  35. new Ideone().teste();
  36. }
  37. }
Success #stdin #stdout 0.11s 32352KB
stdin
Standard input is empty
stdout
Abrindo porta malas
Abrindo porta lateral