"is not abstract and does not override abstract method java" using Decorator Pattern

950 views Asked by At
public abstract class AdicionalesCpd extends Cpd{
public abstract int getCpu();
public abstract int getRam();
public abstract int getDisco();
public abstract String getCadena();}

This my abstract class for the decorator pattern, and I have this problem when it compiles:

**error: Cpu is not abstract and does not override abstract method getCadena() in AdicionalesCpd

public class Cpu extends AdicionalesCpd{ ** I don't know why doesn't override the method "getCpu"

This is my Cpu class which is a "decoration" in the pattern

public class Cpu extends AdicionalesCpd{

Cpd cpd;
int var;

public Cpu(Cpd cpd,int var)
{
    this.cpd=cpd;
    this.var=var;   
}

@Override
public int getCpu() {

    return  cpd.getCpu()+var;

}

}
1

There are 1 answers

1
David On BEST ANSWER

Your abstract base type defines four abstract methods:

public abstract int getCpu();
public abstract int getRam();
public abstract int getDisco();
public abstract String getCadena();

Your concrete derived type implements one of them:

@Override
public int getCpu() {
    return  cpd.getCpu()+var;
}

The error is telling you that you have to implement all of them. Otherwise, what would happen when code invokes one of those methods on an instance of the concrete type?