Given the following class definition fragments and class instantiations, complet
ID: 3682795 • Letter: G
Question
Given the following class definition fragments and class instantiations, complete the table below.
Assume that the methods shown here do not appear in any other classes. (E.g., the Restaurant class does not define a toString method.)
class Building { public Point getLocation() ... }
class Restaurant extends Building { public int getSeatCount() ... }
class Lab extends Building { public String toString() ... }
class Diner extends Restaurant { public boolean equals(Object other) ... }
Lab l = new Lab();
Restaurant r = new Diner();
Building b = l;
Object o = r;
In each blank cell, indicate what would happen if the method in each column is invoked with the object obj in each row. Choose (only one) from the following.
• compiler error
• runtime error (i.e., an exception is thrown)
• X, where X is the class from which the method is called
The first row has been done for you, as a example.
Explanation / Answer
obj obj.getLocation() obj.getSeatCount() obj.toString() obj.equals(obj)
b Building Compiler error Lab Object
l Building compiler error Object Object
o compiler error compiler error Object Object
r Building Restaurant Object Object
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.