Presentation is loading. Please wait.

Presentation is loading. Please wait.

Clicker questions 10/3/13 CSE 1102 Fall 2013. public class { … private _ ; public ) { … _ = ; … } … } In the above code, what is the purpose of the parameter.

Similar presentations


Presentation on theme: "Clicker questions 10/3/13 CSE 1102 Fall 2013. public class { … private _ ; public ) { … _ = ; … } … } In the above code, what is the purpose of the parameter."— Presentation transcript:

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

2 public class { … private _ ; public ) { … _ = ; … } … } In the above code, what is the purpose of the parameter ? A.It sets a default value for _ object B.It is used to initialize _ when we instantiate a C.It is used to instantiate _ when we instantiate a D.It lets us change the value of _container in an existing instance E.All of the above public class HatPart { … private Hat _myHat; public HatPart(Hat aHat){ … _myHat= aHat; … } … } In the above code, what is the purpose of the parameter aHat? A.It sets a default value for _myHat object B.It is used to initialize _myHat when we instantiate a HatPart [correct] C.It is used to instantiate _myHat when we instantiate a HatPart D.It lets us change the value of _myHat in an existing HatPart instance E.All of the above

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

4 In the code above, which move method gets executed? A.The move method defined in OilTanker B.The move method defined in Truck C.The move method defined in Vehicle D.All of the above E.The code does not work [correct] … OilTanker oily = new Truck(200); … oily.move();

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

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

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

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 The formal parameter type for add in Holder is Holdable. What does that require in any non-abstract class that implements Holder? A.It has a method add whose formal parameter type implements Holdable B.The definition of its add method has signature add(Holdable) [correct] C.It will not compile, since Holdable is an interface, not a class. D.It has an abstract add method E.None of the above public interface Holder { void add(Holdable h); Holdable release(); } public interface Holdable { Weight getWeight); Dimension getDimensions(); }


Download ppt "Clicker questions 10/3/13 CSE 1102 Fall 2013. public class { … private _ ; public ) { … _ = ; … } … } In the above code, what is the purpose of the parameter."

Similar presentations


Ads by Google