Błąd w teście w książce przygotowującej do OCA

0

Witam, robię test z książki przygotowującej do OCA. Mam w nim takie pytanie(skopiowane):

2. What is the output of the following code?
1: class Mammal {
2:    public Mammal(int age) {
3:       System.out.print("Mammal");
4:    }
5: }
6: public class Platypus extends Mammal {
7:    public Platypus() {
8:       System.out.print("Platypus");
9:    }
10:    public static void main(String[] args) {
11:       new Mammal(5);
12:    }
13: }
A. Platypus
B. Mammal
C. PlatypusMammal
D. MammalPlatypus
E. The code will not compile because of line 8.
F. The code will not compile because of line 11

Zaznaczyłem B. W odpowiedziach natomiast jest:

2. E. The code will not compile because the parent class Mammal doesn’t define a no-argument
constructor, so the first line of a Platypus constructor should be an explicit call
to super(int age). If there was such a call, then the output would be MammalPlatypus,
since the super constructor is executed before the child constructor

Wtf? Co ma piernik do wiatraka? Zrobiłem taką sturkturę w IDE, kompiluje i wypisuje Mammal..
Czy to nie jest błąd w książce?

0

Źle przepisałeś. Brakuje Ci tego, że klasa Platypus rozszerza (dziedziczy po) klasę Mammal.
Wtedy, trzeba wywołać konstruktor klasy nadrzędnej w konstruktorze klasy podrzędnej

0

racja dziekuje za odpowiedz

1 użytkowników online, w tym zalogowanych: 0, gości: 1