Well, the code you posted is missing a closing "}" before "class Dog", and it references something called "Srting". Those are the trivial problems. Once you fix those, the Dog class still won't compile. Can you tell us why that is?
This is indeed a tricky question. After eliminating the typos already mentioned by Ulf you get the following three classes as a starting point:
The code doesn't compile, because you've implemented a constructor with an non-empty argument list in Animal, but Dog requires a constructor with no arguments. Just to be clear: The compiler adds a Dog()-constructor along with a super()-call when Dog is compiled. This super()-call needs an Animal()-construtor, but it doesn't exist!! Note: the compiler adds a non-argument-constructor at compile-time only if there is no other constructor implemented.
Following two alternatives to solve the problem (class Test always stays unchanged): 1. Implement a constructor in Dog that explicitly calls the Animal(String)-constructor:
Note: don't forget super(name), since otherwise the compiler would add a super() call - and Animal() doesn't exist!
2. Implement an non-argument constructor in Animal
Animal() will be invoked in case you instantiate Dog or if you execute new Animal();
Yup, yup, yup. Tiny ad:
a bit of art, as a gift, that will fit in a stocking