shapetest.java
来自「《Java核心技术应用开发》电子工业出版社书籍源代码」· Java 代码 · 共 66 行
JAVA
66 行
package sample;
public class ShapeTest {
public ShapeTest() {
}
public static void main(String[] args) {
//ShapeTest shapeTest1 = new ShapeTest();
Shape[] s={new Shape(1,4),
new Rectangle(1,2,3,4),
new Circle(2,3,5)};
for(int k = 0; k < s.length; k++){
s[k].draw();
}
/*
Circle c = new Circle(1,2,3);
c.draw();
*/
}
}
class Shape{
protected int x;
protected int y;
//public Shape(){}
public Shape(int x, int y){
this.x = x;
this.y = y;
}
public void draw(){System.out.println("This is a test in shape......");}
}
class Rectangle extends Shape{
private int heigth;
private int weight;
public Rectangle(int x, int y, int w, int h){
super(x,y);
this.weight = w;
this.heigth = h;
}
public void draw(){System.out.println("This is a test in Rectangle.");}
}
class Circle extends Shape{
private int r;
public Circle(int x, int y, int r){
super(x,y);
this.r = r;
}
public void draw(){System.out.println("This is a test in Circle.");}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?