public class CPU {
int speed;
public int getSpeed() {
return speed;
}
public void setSpeed(int m) {
speed=m;
}
int speed;
public int getSpeed() {
return speed;
}
public void setSpeed(int m) {
speed=m;
}
}
public class HardDisk {
int amount;
public int getAmount() {
return amount;
}
public void setAmount(int m) {
amount=m;
}
}
public class PC {
CPU cpu;
HardDisk HD;
public void setCPU(CPU c) {
cpu=c;
}
public void setHardDisk(HardDisk h) {
HD=h;
}
public void show(){
System.out.println("cpu的速度:"+cpu.getSpeed()+"硬盘的容量:"+HD.getAmount());
}
}
public class Test {
public static void main(String[] args) {
CPU cpu=new CPU();
cpu.setSpeed(2200);
HardDisk disk=new HardDisk();
disk.setAmount(200);
PC pc=new PC();
pc.setCPU(cpu);
pc.setHardDisk(disk);
pc.show();
}
}