将上述代码的输出结果改成先输出大号毛笔
时间: 2024-03-09 15:51:04 浏览: 123
可以将Pen类中的代码改为如下所示,先实例化大号毛笔并输出,再实例化中号和小号毛笔并输出:
```
public class Pen {
public static void main(String[] args){
Color Red = new Red();
Brush BigBrush = new BigBrush();
BigBrush.setColor(Red);
System.out.println("大号毛笔:");
BigBrush.operation();
Color Green = new Green();
Brush MidBrush = new MidBrush();
MidBrush.setColor(Green);
System.out.println("中号毛笔:");
MidBrush.operation();
Color Blue = new Blue();
Brush SmallBrush = new SmallBrush();
SmallBrush.setColor(Blue);
System.out.println("小号毛笔:");
SmallBrush.operation();
}
}
```
这样输出的结果就是先输出大号毛笔的操作,再输出中号和小号毛笔的操作。
阅读全文
相关推荐















