Ola pessoal. Estava fazendo o simulado do Whizlab e a primeira pergunta é a seguinte:
Which of the following methods inserted independently at the indicated line in the following code can cause it to compile correctly?
class SuperBase {}
class Base extends SuperBase{}
class Derived extends Base{}
class CovariantTest1{
public Base getIt(){ return new Base();}
class SubCovariantTest extends CovariantTest1{
//insert code here
}
Select any two options:
A: public Derived getIt(){ return new Derived();}
B: public Base getIt(){ return new Derived();}
C: public SuperBase getIt(){ return new Derived();}
D: public SuperBase getIt(){ return new Base;}
E: public Derived getIt(){ return new Base();}
No resultado, ele diz que as respostas certas são a letra A e B, mas ao tentar compilar utilizando estas respostas, o compilador me mostrou o seguinte erro ao tentar compilar com a resposta A:
The return type is incompatible with CovariantTest1.getIt()
A resposta B compila certo.
Nao entendi o porque…
Se alguem souber agradeço.