Exploring - yorkie.avgBreedWeight()); The problem is that...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Solutions to Exploring Inheritance Complete Dog class: Dog.java Complete Labrador class: Labrador.java Complete Yorkshire class: Yorkshire.java Complete DogTest program DogTest.java 1. Since the Labrador constructor does not contain an explicit call to the constructor for the superclass (Dog), the compiler inserts a call to the default (0-parameter) constructor for Dog. But Dog does not have such a constructor, hence the error. 2. The error is this: DogTest.java:22: cannot resolve symbol symbol : method avgBreedWeight () location: class Yorkshire System.out.println("The average breed weight for a yorkshire is " +
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: yorkie.avgBreedWeight()); The problem is that the Yorkshire class does not have an avgBreedWeight method, and there is not one in Dog for it to inherit. 3. The first error is this: ./Dog.java:7: Dog should be declared abstract; it does not define avgBreedWeight() in Dog public class Dog The solution is to make the Dog class abstract. But this produces the error below: DogTest.java:12: Dog is abstract; cannot be instantiated Dog dog = new Dog("Spike"); Since Dog is abstract, we cannot create a Dog object. This line must be removed from DogTest.java....
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Ask a homework question - tutors are online