public abstract class House private int size public static int numPeople1; publi
ID: 3903324 • Letter: P
Question
public abstract class House private int size public static int numPeople1; public void temperaturelint cost) public House( Public House(int size} { publia int getsise ( public class UCSDDorm extends House implements Habitable( publia UCSDDorm(int size super (size public UCSDDorm //empty constructor public void repair (double cost) System. out-printin("A lot of money"cost public void temperature int cost ystem.out.println ("temperature atco 10) Assume that the following statements are from a main method in a tester class. Answer whether the following statements will cause a compiler error, a runtime error, or no e all. If there is no error, write the output from the code snippet. These statements are not sequential to each other System.out , printIn(h. getSize () ); 9ystem out println(r.numPeople); l VersionA Answer Answer 4 Habitable p new UC3DDorm (100) 3ystem.out-printin(p.getsise Answer s.repair (3.14); Answer Version A I House Pnew UCSDDorm) System-out-println ( p.temperature (12) Habitable h new UCSDDorm 3ystem. out println House)h) getsize) Answer ); Version A AnswerExplanation / Answer
5) Reason for question 5 for not getting error is we are casting h to type House which is derived downcasting. So eventhough h is of type Habitable as we have casted that to house it will call the getSize() of class House class which was inherited to the USCDorm class. By casting it will be clear to the compiler which method to call so it will not cause compile error. As we have casted now compiler will look for getSize() inHouse class.
6) Reson for casing error in this class is we have not casted the reference variable P which is of type House eventhough it was holdingUSCDorm type. If we didnot cast it will look into House class for the temperature() but itwas not there in that class. Thats why it will give compile error.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.