In this homework, you are asked to depict the contents of memory (RAM) at a specific point during the execution of the Pets program. Download Pets.jar which contains a version of the Pets program that is very similar to the one developed in class. Feel free to run the program; you can also observe the execution of the program using the netBeans debugger.
Your diagram is to depict memory immediately before the execution of the line of code indicated below.
public class Pets
{
public static void main (String [] args)
{
String dogName = new String("spike");
String catName = new String("tom");
Cat tom = new Cat(catName);
Dog spike = new Dog(dogName);
spike.bite(tom); ***THIS LINE***
}
}
For 5 points extra credit (15 points total for this assignment), you can also diagram memory immediately before the execution of this line of code:
public class Dog
{
...
public void bite(Cat catmeat)
{
growl(); ***THIS LINE***
if (beenScratched < 3) {
beenScratched++;
System.out.println(name + " is bitting " + catmeat.getName());
catmeat.scratch(this);
}
else {
System.out.println(name + " is running away!");
yelp();
}
}
...
}
Turn in a hard copy of your memory diagram(s) at the start of the next class.