处理器类
public class Cpu {public void start() {System.out.println("处理器启动了...");}
}
内存类
public class Memory {public void start() {System.out.println("内存启动了...");}
}
硬盘类
public class Disk {public void start() {System.out.println("硬盘启动了...");}
}
电脑类
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("电脑启动完毕");}
}
演示类
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();}
}
演示结果