Including partition Object when drawing objects
This self-exercise is to include a partition for class Object when drawing objects. Here are the answers, in a pdf file.
Step 1. Draw an object.
Consider the following classes:
public class Ex {
public static final int ZERO= 0;
private int h;public Ex(int ph) {
h= ph;
}public int getH() {
return h;
}public String toString() { ... }
public static int what(int x) { ... }
}public class Sub extends Ex {
private int k;public Sub(int pk) {
k= pk;
}public String toString() { ... }
}
To the right is an instance of class Sub. Below the horizontal line are all the instance variables and methods that are declared in Sub; above the line are all the instance variables and methods that are declared in superclass Ex. Variables h and k have been given arbitrary values.
On your paper, draw an instance of class Ex and another instance of class Sub; this time, include in each object you draw the partition for class Object.
Step 2. More subclasses
Consider also these two subclasses of class Sub:
public class SubSub1 extends Sub {
public SubSub1() {
super(5);
}public int hPlus1() {
return getH()+1;
}public String toString() { ... }
}public class SubSub2 extends Sub {
private int p;
}
Draw an intance of class SubSub1 and an instance of class SubSub2; this time, include in each object the partition for class Object.