public static void main(String[] args) {
Shape[] shapes = {new Cycle(),new Rect(),new Flower(),new Rect()};
for (Shape shape : shapes) {//其中,冒号的前方只是用一个未知数接替数组一个个传来的值,主要的还是花括号的代码
shape.draw();
}
for each的使用
最新推荐文章于 2024-09-05 11:00:53 发布
本文展示了如何在Java中使用一个Shape数组,通过循环调用`draw()`方法来绘制不同类型的图形,如Cycle、Rect和Flower。
摘要由CSDN通过智能技术生成