Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Questions 9 & 10 refer to the following Horse, WorkHorse, and Race Horse classes public class Horse { private int age; private double price; public
Questions 9 & 10 refer to the following Horse, WorkHorse, and Race Horse classes public class Horse { private int age; private double price; public Horse(int a, double p) { //constructor age = a; price = p; } public int getAge() { return age; } public double getPrice() { return price; } price void setAge(int newAge) { age = newAge; } public void setPrice (double newPrice) { price = new Price; } public void have Birthday() { age++; price = price - .1 * price; }} public class WorkHorse extends Horse { private double weight; //constructor public WorkHorse(int a, double p, double w) { super(a, p); weight = w; } } public class RaceHorse extends Horse { //constructor public RaceHorse(int a, double p) { superla, p); } public void haveBirthday() { setAge(getAge( ) + 1); setPrice(getPricel)-.2 * getPrice()); } ] } 9. Which of the following statements will compile without error? A. Horse h = new WorkHorse(2, 1000); B. Horse h = new Race Horse(2, 1000); C. WorkHorse h = new RaceHorse(2, 1000); D. RaceHorse h = new WorkHorse(2, 1000); E. Race Horse h = new Horse(2, 1000); 10. Assume that variable h has been declared to be of type Horse, & has been initialized to represent a horse whose price is 100. Which of the following statements about the call h.haveBirthday() is true? A. Whatever kind of horse variable h actually points to, the price of that horse after the call will be 90. B. Whatever kind of horse variable h actually points to, the price of that horse after the call will be 80. C. If variable h actually points to a RaceHorse object, then the price of that horse after the call will be 80. D. If variable h actually points to a WorkHorse object, there will be a runtime error, since class WorkHorse has no havebirthday method. E. If variable h actually points to a WorkHorse object, the price of that horse after the call will still be 100, since class WorkHorse has no havebirthday method
Step 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