What happens when you try to compile the following code and run the Horse application?
class Animal { /*w ww .j a v a2s . c o m*/ float weight; Animal(float weight) { this.weight = weight; } } class Horse extends Animal { public static void main(String[] args) { Animal a = new Animal(222.2f); Horse z = new Horse(); } }
B.
Class Animal has no no-args constructor.
Class Horse has no constructor at all, so the compiler creates one that just calls the superclass' no-args constructor.
Since there is no such constructor, compilation fails.