1
Suppose I have the following hierarchical structure in Java:
First a class Avo
:
public class Avo {
protected String nome;
public void falar() {
//Codigo aqui
}
}
Next I have a class Pai
who inherits from Avo
and overwritten his method of speaking:
public class Pai extends Avo {
@Override
public void falar() {
//Codigo aqui
}
}
I finally have a class Filho
who inherits from Pai
and once again overrides the method to speak:
public class Filho extends Pai{
@Override
public void falar() {
//Chamar método falar da classe Avo
//Resto da implementação
}
}
Is there any way in the method to speak of the class Filho
call the method speak of the superclass Avo instead of the superclass method Pai
? I know in C++ can do Avo::falar()
, has something similar in Java?
Jon Skeet says this is a bad idea to do
– user28595
This violates encapsulation and is not allowed in Java. You can even do a gambit (don’t!), but depending on what you want, there may be other, simpler ways.
– Valdeir Psr
I get it, thank you.
– Jônatas Trabuco Belotti