This is an annotated solution to Team code tracing assignment.  Notice these apply to the updated version of the Team problem, which is found online. The exact solution is shown in italics

1) We select Giants since we have asked for teamA.getName(), not teamB.getName()
Giants

2) A variable can only hold one value, so when the Weak sauce team is created, the Strong Waffles team is no longer refered to.  Since nobody refers to the Strong Waffles team, it will be garbage collected (and the String "Strong Waffles" will also be garbage collected)
Mild sauce

3)  Notice we can chain things together--we can use a return value as part of a sum and the result of a sum in a parameter.  The plus sign used with at least one String means concatenation--a fancy word meaning "glue the ends together."  For example, "dad" concatenated with "dies" is "daddies."
Geek Squad 20

4) The key here is that there is only one team that was created, and both teamA and teamB refer to the same team.  The assignment copies the value of teamA, but the value of teamA is just a reference to the Team object with the name "Mighty Ducks."  Thus teamB will also refer to the same object.  When the change skill is called, it will be called on the same team twice.  And since they refer to the same object, clearly the last two lines will print the same thing.
111
111

5) When we pass food in as a parameter, we aren't really passing in the variable food.  We also aren't passing in the value "muffinS".  We are passing in a reference to  "muffinS" (the same one that food refers to).  However, changing food later just means that it points somewhere else--the name field of our Team did not change.  Thus at the end, the Team name is still "muffinS" and food is now "hot dog".  Notice that we used print() instead of println() and there is no space between the two Strings.
muffinShot dog

6) The Team starts with a value of 12.  We later change skillz to 18, but it is worth noting that changing the value of the int skillz does not change the skill of the Team--we only passed in the value of skillz, which was 12.  So the final value of skillz is 18 and the final value of the Team's skill is 12 + 18, or 30.
18
30

7) This is another demonstration of using the return value of a function as a parameter to another function.  Any expression of a given type can be used where any other expression of the same type.  Since "Josh" and tame.getName() and "meta"+tame.getName() are all expressions with the type String, I can say tame.setName("Josh") and tame.setName("meta" + tame.getName()).
metameat

Last updated 2-12-2008