代码
/*
开放型题目:
设计一个笔记本电脑类,属性随意,并且进行属性私有化,对外提供公开的set和get方法。
设计一个可插拔的接口:InsertDrawable,该接口有什么方法自行定义。
设计一个鼠标类,实现InsertDrawable接口,并实现方法。
设计一个键盘类,实现InsertDrawable接口,并实现方法。
设计一个显示器类,实现InsertDrawable接口,并实现方法。
设计一个打印机类,实现InsertDrawable接口,并实现方法。
在“笔记本电脑类”中有一个InsertDrawable接口属性,可以让笔记本
电脑可插拔鼠标、键盘、显示器、打印机等。
编写测试程序,创建多个对象,演示接口的作用。
*/
public class Homework1 {
public static void main(String[] args) {
//创建鼠标、键盘、显示器、打印机对象
InsertDrawable mouse = new Mouse();
InsertDrawable keyboard = new Keyboard();
InsertDrawable display = new Display();
InsertDrawable printer = new Printer();
//创建电脑对象
Computer c = new Computer();
//将鼠标、键盘、显示器、打印机插入电脑
c.getSlot()[0] = mouse;
c.getSlot(