Presentation is loading. Please wait.

Presentation is loading. Please wait.

Clicker questions 10/3/13 CSE 1102 Fall 2013.

Similar presentations


Presentation on theme: "Clicker questions 10/3/13 CSE 1102 Fall 2013."— Presentation transcript:

1 Clicker questions 10/3/13 CSE 1102 Fall 2013

2 public class <PartClass> {
private <ContainerClass> _<container>; public <PartClass(<ContainerClass> <aContainer>) { _<container> = <aContainer>; } public class HatPart { private Hat _myHat; public HatPart(Hat aHat){ _myHat= aHat; } In the above code, what is the purpose of the parameter aHat? It sets a default value for _myHat object It is used to initialize _myHat when we instantiate a HatPart It is used to instantiate _myHat when we instantiate a HatPart It lets us change the value of _myHat in an existing HatPart instance All of the above In the above code, what is the purpose of the parameter <aContainer>? It sets a default value for _<container> object It is used to initialize _<container> when we instantiate a <PartClass> It is used to instantiate _<container> when we instantiate a <PartClass> It lets us change the value of _container in an existing <PartClass> instance All of the above

3 Notice from the diagram that Rectangle is not linked to Draggable
Notice from the diagram that Rectangle is not linked to Draggable. What does this imply? HatPart must define all of the Draggable methods independent of Rectangle Someone forgot to put the link in the diagram Rectangle.java does not include the phrase implements Draggable Either A or B above Either B or C above

4 OilTanker oily = new Truck(200); oily.move(); In the code above, which move method gets executed? The move method defined in OilTanker The move method defined in Truck The move method defined in Vehicle All of the above The code does not work

5 private Tree _tree; ... _tree = new Oak(); _tree.prepareForWinter(); Given the above class diagram, and the code on the right, what happens when the last line (_tree.prepareForWinter();) is executed? The prepareForWinter method defined in Oak is used The prepareForWinter method defined in Pine is used The prepareForWinter method defined in Tree is used The last line does not get executed since _tree = new Oak(); causes an error None of the above

6 public class Crow extends Bird {
private Tree _myTree; ... public void battenDown(){ _myTree.??? } Suppose Russell is a Crow, and lives in an Oak. What can replace ??? above? prepareForWinter(); absorbWater(); dropLeaves(); Any public method from Tree or anything above it in the inheritance hierarchy Any public method from Oak or anything above it in the inheritance hierarchy

7 public class Oak extends Tree {
... public void prepareForWinter(){ this.dropLeaves(); ??? } Suppose an Oak prepares for winter like a Tree, but it drops its leaves first. What code should replace ??? above? Tree.prepareForWinter(); super.this(); super.prepareForWinter(); this.absorbWater(); super(this);

8 Example: Death Race 2000 Your task: to produce a new video game. It works by instantiating a DeathRace between 2 cars using the constructor, then calling its runTheRace method, which returns the winner. public class DeathRace { Car _car1, _car2; public DeathRace(Car c1,Car c2){ _car1 = c1; _car2 = c2; ... } public Car runTheRace(){ Car winner; _car1.move(); _car2.move(); return winner;

9 Car

10 public interface Holder {
void add(Holdable h); Holdable release(); } public interface Holdable { Weight getWeight); Dimension getDimensions(); } The formal parameter type for add in Holder is Holdable. What does that require in any non-abstract class that implements Holder? It has a method add whose formal parameter type implements Holdable The definition of its add method has signature add(Holdable) It will not compile, since Holdable is an interface, not a class. It has an abstract add method None of the above


Download ppt "Clicker questions 10/3/13 CSE 1102 Fall 2013."

Similar presentations


Ads by Google