📄 testpolymorphism.java
字号:
/*
* TestPolymorphism.java E.L. 2001-08-17
*
*/
class TestPolymorphism {
public static void main(String[] args) {
Material[] materials = new Material[5];
materials[0] = new Paint("Heimdal Super", 20, 2, 10);
materials[1] = new Wallpaper("Brocade77", 50, 12, 0.6);
materials[2] = new Paint("Heimdal Extra", 10, 3, 10);
materials[3] = new Flooring("Wool-Gold", 45, 5);
materials[4] = new Flooring("Soft-Gold", 30, 5);
Surface aSurface = new Surface("testSurface", 4, 5);
for (int i = 0; i < materials.length; i++) {
String name = materials[i].getName();
double req = materials[i].getMaterialReq(aSurface);
double price = materials[i].getTotalPrice(aSurface);
System.out.println("Name: " + name + ", Requirement: "
+ req + " units, Price $" + price);
}
}
}
/* Example Run:
Name: Heimdal Super, Requirement: 4.0 units, Price $80.0
Name: Brocade77, Requirement: 4.0 units, Price $200.0
Name: Heimdal Extra, Requirement: 6.0 units, Price $60.0
Name: Wool-Gold, Requirement: 5.0 units, Price $225.0
Name: Soft-Gold, Requirement: 5.0 units, Price $150.0
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -