public class CPU {
int speed;
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
}
public class HardDisk {
int amount;
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
}
public class PC {
CPU cpu;
HardDisk HD;
public CPU getCpu() {
return cpu;
}
public void setCpu(CPU cpu) {
this.cpu = cpu;
}
public HardDisk getHD() {
return HD;
}
public void setHD(HardDisk hD) {
this.HD = hD;
}
void Show() {
System.out.println("CPU频率"+cpu.getSpeed());
System.out.println("硬盘容量"+HD.getAmount());
}
}
package org.gerrysu.Test5;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
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();
}
}