fork download
  1. import java.util.ArrayList;
  2.  
  3. class Ideone {
  4. public static void main (String[] args) {
  5. ArrayList<Pessoa> pessoas = new ArrayList<>();
  6. pessoas.add(new Pessoa(1, "joão", 'M', "9999-9999"));
  7. pessoas.add(new Pessoa(2, "maria", 'F', "9999-9991"));
  8. for (Pessoa pessoa : pessoas) System.out.println(pessoa.getNome());
  9. }
  10. }
  11.  
  12. class Pessoa {
  13. private int id;
  14. private String nome;
  15. private char sexo;
  16. private String telefone;
  17.  
  18. Pessoa(int id, String nome, char sexo, String telefone){
  19. this.id = id;
  20. this.nome = nome;
  21. this.sexo = sexo;
  22. this.telefone = telefone;
  23. }
  24.  
  25. public int getId() { return this.id; }
  26. public void setId(int id) { this.id = id; }
  27.  
  28. public String getNome(){ return this.nome; }
  29. public void setNome(String nome) { this.nome = nome; }
  30.  
  31. public char getSexo() { return this.sexo; }
  32. public void setSexo(char sexo) { this.sexo = sexo; }
  33.  
  34. public String getTelefone() { return this.telefone; }
  35. public void setTelefone(String telefone) { this.telefone = telefone;}
  36. }
  37.  
  38. //https://pt.stackoverflow.com/q/123921/101
Success #stdin #stdout 0.06s 32216KB
stdin
Standard input is empty
stdout
joão
maria