public class Hockey { public static void main (String[] args) { Skater helen = new Skater (5, "blue"); Goalie brenda = new Goalie (29, "red"); helen.scoreGoal (brenda); (new Skater(55,"green")).scoreGoal(brenda); int total = helen.getGoals(); System.out.println ("Goals by Helen: " + total); } } class Skater { private int num; private String team; private int goals; public Skater (int number, String teamname) { num = number; team = teamname; } public void scoreGoal (Goalie goalie) { goals++; goalie.recordGoal(); } public int getGoals() { return goals; } } class Goalie { private int num; private String team; private int goalsAgainst; public Goalie (int mynum, String myteam) { num = mynum; team = myteam; } public void recordGoal() { goalsAgainst++; } }
Show what happens in memory...