P121-4(1)
package java02;
class Lake{
Fish fish;
void setFish(Fish s) {
fish = s;
}
void foodFish(int m) {
fish.weight = fish.weight + m;
}
Fish getFish() {
fish.weight -=10;
return fish;
}
}
public class E {
public static void main(String args[]) {
Fish redFish = new Fish();
Lake lake =new Lake();
lake.setFish(redFish);
lake.foodFish(120);
int w = lake.fish.weight;
Fish fishOK=lake.getFish();
System.out.printf("%d:%d:%d",w,lake.fish.weight,fishOK.weight);
}
}
class Fish{
int weight=1;
}
P123-5(1)
package java02;
class AAA {
static int m;
static {
m=888;
}
}
class E {
public static void main(String[] args) {
AAA a=null;
System.out.printf("%d:%d",AAA.m,a.m);
}}