CPU模拟:
public class CPU {
int speed;
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public CPU(int speed) {
this.speed = speed;
}
}
硬盘模拟:
public class HardDisk {
int amount;
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public HardDisk(int amount) {
this.amount = amount;
}
}
运行模拟:
package test;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
CPU cpu=new CPU(6666);
HardDisk harddisk=new HardDisk(8888);
computer pc=new computer();
pc.setCpu(cpu);
pc.setHarddisk(harddisk);
pc.show();
}
}
HardDisk harddisk=new HardDisk(8888);
computer pc=new computer();
pc.setCpu(cpu);
pc.setHarddisk(harddisk);
pc.show();
}
}
结果: