I can’t seem to instantiate an object

Asked

Viewed 140 times

-2

I’m unable to instantiate an object from the Student class

Pupil Class

public class Aluno extends Pessoa
{
    private int matricula;

    public Aluno(int id, String nome, String endereco, String telefone, String email, int matricula) {
        super(id, nome, endereco, telefone, email);
        this.setMatricula(matricula);
    }

    public Aluno()
    {

    }

    public int getMatricula() {
        return matricula;
    }

    public void setMatricula(int matricula) {
        this.matricula = matricula;
    }
}

Classe Pessoa

abstract public class Pessoa 
{
    private int id;
    private String nome;
    private String endereco;
    private String telefone;
    private String email;

    public Pessoa(int id, String nome, String endereco, String telefone, String email) {
        this.id = id;
        this.nome = nome;
        this.endereco = endereco;
        this.telefone = telefone;
        this.email = email;
    }

    public Pessoa() {
        super();
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    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;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}

As I am trying to instantiate an object of the class Student but without success

                    System.out.println("ID aluno:");
                    int id = input.nextInt();
                    System.out.println("Nome:");
                    String nome = input.next();
                    System.out.println("Endereço:");
                    String endereco = input.next();
                    System.out.println("Número:");
                    String numero = input.next();
                    System.out.println("Email:");
                    String email = input.next();
                    System.out.println("Matrícula:");
                    int matricula = input.nextInt();
                    aluno = new Aluno(id,nome,endereco,numero,email,matricula);
                    System.out.println("Deseja cadastrar um novo aluno?(1-Sim/2-Não):");
                    op = input.nextInt();
                    AL.add(aluno);
  • 2

    Please [Edit] the question and ask what is the error that occurs, if it is build error, any exception which occurs during execution (which message and which data caused the error), etc.

1 answer

0

In java you must tell what type of object is being created, so it should be done like this:

Aluno aluno = new Aluno(id,nome,endereco,numero,email,matricula);
  • It’s not like that, mate

  • @Cassia and what error returns you?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.