📄 useshapes.java
字号:
/*
* Created on 2005-10-9
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package polymorphism;
/**
* From 'Thinking in Java, 2nd ed.' by Bruce Eckel
*/
public class UseShapes {
public static Shape randShape() {
switch ((int) (Math.random() * 3)) {
default:
case 0:
return new Circle();
case 1:
return new Square();
case 2:
return new Triangle();
}
}
public static void main(String[] args) {
Shape[] s = new Shape[9];
// Fill up the array with shapes:
for (int i = 0; i < s.length; i++)
s[i] = randShape();
// Make polymorphic method calls:
for (int i = 0; i < s.length; i++)
s[i].draw();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -