public class Cpu {
public void start() {
System.out.println("处理器启动了...");
}
}
1.
2.
3.
4.
5.
内存类
public class Memory {
public void start() {
System.out.println("内存启动了...");
}
}
1.
2.
3.
4.
5.
硬盘类
public class Disk {
public void start() {
System.out.println("硬盘启动了...");
}
}
1.
2.
3.
4.
5.
电脑类
public class Computer {
private Cpu cpu;
private Memory memory;
private Disk disk;
public void start() {
System.out.println("电脑启动中...");
cpu.start();
memory.start();
disk.start();
System.out.println("电脑启动完毕");
}
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
演示类
public class Demo {
public static void main(String[] args) {
Computer computer = new Computer();
computer.setCpu(new Cpu());
computer.setMemory(new Memory());
computer.setDisk(new Disk());
computer.start();
}
}