Why do I get an error in this Java abstract class? [closed]

-1
package poo;

import java.util.Date;
import java.util.GregorianCalendar;

public class Uso_Persona {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Persona[] lasPersonas = new Persona[2];

        lasPersonas[0] = new Empleado2("Luis Conde", 50000, 2009, 02, 25);
        lasPersonas[1] = new Alumno("Ana Lopez", "Biológicas");

        for (Persona p: lasPersonas) {

            System.out.println(p.dameNombre() + ", " + p.dameDescripcion());

        }

    }

}

abstract class Persona{

    public Persona(String nom) {

        nombre = nom;

    }

    public String dameNombre() {

        return nombre;

    }

    public abstract String dameDescripcion();

    private String nombre;

}

class Empleado2 extends Persona{

    public Empleado2(String nom, double sue, int agno, int mes, int dia) {

        super(nom);

        sueldo = sue;

        GregorianCalendar calendario = new GregorianCalendar(agno, mes-1, dia);

        altaContrato = calendario.getTime();

        ++IdSiguiente;

        Id = IdSiguiente;
    }

    public String dameDescipcion(){

        return "Este empleado tiene un Id= " + Id + " con un sueldo= "
                + sueldo;

    }

    public double dameSueldo() { // getter

        return sueldo;

    }

    public Date dameFechaContrato() {

        return altaContrato;

    }

    public void subeSueldo(double porcentaje) { // setter

        double aumento = sueldo*porcentaje/100;

        sueldo += aumento;

    }


    private double sueldo;

    private Date altaContrato;

    private static int IdSiguiente;

    private int Id;

}

class Alumno extends Persona{

    public Alumno(String nom, String car) {

        super(nom);

        carrera = car;

    }

    public String dameDescripcion() {

        return "Este alumno está estidiando la carrera de"+ carrera;

    }

    private String carrera;

}

The error is:

" Exception in thread" main "java.lang.Error: Unresolved compilation problem:     The type Employee2 must implement the inherited abstract method Person.dameDescription () "

But as you can see the abstract method to which it refers is included.

    
asked by José Ignacio 26.04.2018 в 00:22
source

1 answer

3

The error occurs because the name of the method in Empleado2 does not match that of the parent. In Empleado2 you declare as dameDescipcion() , if you realize you need a r between the first c and the i of the word description. Correctly type the name of the method and you're done.

To avoid this kind of errors, use the @Override notation which forces compile time to check that a method is overwriting one on its parent.

See my answer to this post where I explain a little better the use of @Override .

    
answered by 26.04.2018 / 00:28
source