package java2;
public class CPU {
int speed;
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
}
package java2;
public class HardDisk {
int amount;
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
}
package java2;
public class PC {
CPU cpu;
HardDisk HD;
public void setCpu(CPU cpu) {
this.cpu = cpu;
}
public void setHD(HardDisk hD) {
HD = hD;
}
void show()
{
System.out.println("cpu速度:"+cpu.speed+"硬盘容量:"+HD.amount);
}
}
package java2;
public class Test {
public static void main(String[] args) {
// TODO 自动生成的方法存根
CPU cpu=new CPU();
cpu.setSpeed(2200);
HardDisk disk= new HardDisk();
disk.setAmount(200);
PC pc = new PC();
pc.setCpu(cpu);
pc.setHD(disk);
pc.show();
}
}