0
I have a super class Person with 2 sub classes (Student and Teacher). However I made another class "List" to create Arraylist and later handle everything.
When using the List the data is accepted but when I try to read the contents of the list what is shown me is wrong.
The code is as follows: Pupil Class
package aula38;
public class Aluno extends Pessoa { //extend permite usar campos da classe a que se extende
    private String curso;
    private double notas;
    //public Aluno(String nome, String endereco, String telefone, String curso) {     }
    public Aluno(String curso, String nome, String endereco, String telefone) {
        super(nome, endereco, telefone);
        this.curso = curso;
       // this.notas = notas;
    }
    public String getCurso() {
        return curso;
    }
    public void setCurso(String curso) {
        this.curso = curso;
    }
    public double getNotas() {
        return notas;
    }
    public void setNotas(double notas) {
        this.notas = notas;
    }
}
Professor Class
package aula38;
public class Professor extends Pessoa {
    private double salario;
    private String nomeCurso;
    /**
     *
     * @param salario
     * @param nomeCurso
     * @param nome
     * @param endereco
     * @param telefone
     */
    public Professor(double salario, String nomeCurso, String nome, String endereco, String telefone) {
        super(nome, endereco, telefone);
        this.salario = salario;
        this.nomeCurso = nomeCurso;
    }
    public double getSalario() {
        return salario;
    }
    public void setSalario(double salario) {
        this.salario = salario;
    }
    public String getNomeCurso() {
        return nomeCurso;
    }
    public void setNomeCurso(String nomeCurso) {
        this.nomeCurso = nomeCurso;
    }
}
Classe Pessoa
package aula38;
import java.util.ArrayList;
public class Pessoa {
    private String nome;
    private String endereco;
    private String telefone;
    public Pessoa(String nome, String endereco, String telefone) {
        this.nome = nome;
        this.endereco = endereco;
        this.telefone = telefone;
    }
    public String getNome() {
        return nome;
    }
    public void setNome(String nome) {
        this.nome = nome;
    }
    public String getEndereco() {
        return endereco;
    }
    public void setEndereco(String endereco) {
        this.endereco = endereco;
    }
    public String getTelefone() {
        return telefone;
    }
    public void setTelefone(String telefone) {
        this.telefone = telefone;
    }
}
List Class
    package aula38;
import aula38.Pessoa;
import java.util.ArrayList;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Jos
 */
public class Lista {
    private ArrayList<Pessoa> gente;
    public Lista() {
        gente = new ArrayList<>();
    }
    public void adicionarGente(Pessoa a){
        gente.add(a);
    }
    public void Listar(){
        for(Pessoa a: gente){
            System.out.println(a);
        }
    }
}
Class Aula38
package aula38;
public class Aula38 {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    Lista lista = new Lista();
    lista.adicionarGente(new Pessoa("Maria","Rua 2", "92550421"));
    lista.adicionarGente(new Aluno("Luca", "Rua 20", "942110422", "TIC"));
    lista.adicionarGente(new Professor (500, "TIC", "Jorge", "Rua 21", "215225682"));
    lista.Listar(); // nao faz o display correto dos valores acima
    } 
}
And the display is:
Can someone tell me what’s wrong?
