1
With the interface Posicionavel
:
package projeto;
public interface Posicionavel
{
public boolean mesmaPosicao(Posicionavel p);
public boolean mesmaPosicao(int[] x);
public int[] posicoes();
}
And the class Celula
:
package projeto;
public abstract class Celula implements Posicionavel
{
protected String cor;
protected int x, y;
public Celula(int x, int y) {
this.x = x;
this.y = y;
}
public int[] posicoes()
{
return new int[]{x, y};
}
public boolean mesmaPosicao(Posicionavel p)
{
return posicoes().equals(p.posicoes());
}
public boolean mesmaPosicao(int[] x)
{
return posicoes().equals(x);
}
}
The class below will also be an implementation of Posicionavel
?
package projeto;
public class CelulaBoca extends Celula
{
public CelulaBoca(int x, int y)
{
super(x, y);
this.cor = Cores.VERMELHO;
}
}
Does it inherit all attributes even if there is one that is private? For if it does not inherit, the subclass may have "less things"...
– Matheus Guedes
Yes, inherits everything, the
private
just says that the daughter class can’t access the field (and not attribute that it’s wrong term they learned), but it’s there, there’s no way it can’t be. I guess you didn’t read the links that I went through. Almost everyone understands wrong heritage and then ends up using wrong.– Maniero