Question
So I had to answer this question. I picked E - the code does not compile. Here is my thinking: I compile this code on
So I had to answer this question. I picked E - the code does not compile. Here is my thinking: I compile this code on my machine. I wrote out the first three classes: AnimalDriver.java which includes the declaration as well as the two calls to eat and speak. Animal.java contains the Animal class and the main method, with all of the code up to the Dog class, and the Dog.java class has its own file. As soon as I start to type in the first line of SmallDog, it throws this error: "Implicit super constructor Dog() is undefined for default constructor. Must define an explicit constructor." And I think that is because SmallDog is trying to extend it. Dog class can extend Animal because there's a constructor there, but SmallDog cannot extend Dog because Dog does not have its own constructor. Hence, I picked E. But if Smalldog simply extended animal, then it would be D. Do I have that right?
Consider the three classes below. Assume that the following declaration appears in a class other than Dog. Smalldog fido = new Smalldog ("Dachshund"); Assume that the following code appears in this same class. fido.eat(); fido.speak(); public abstract class Animal { private String name; private boolean hungry: public Animal (String nm) { name = n; hungry = true; } public boolean getHungry() { return hungry; } public void eat () { hungry = false; } public void speak () { if (hungry) { System.out.println("The hungry " + name + words () + " + words()); } else { System.out.println("The full " + name + says words()); } } IT IT + + What is printed as a result?: A) Yip-Yip B) Bow-wow C) The hungry Dachshund says Yip-Yip Yip-Yip D) The full Dachshund says Yip-Yip E) This code generates a compilation errorStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started