You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
735 B
38 lines
735 B
package com.example.shape;
|
|
|
|
class Shape {
|
|
public void draw() {
|
|
System.out.println("绘制形状");
|
|
}
|
|
}
|
|
|
|
class Circle extends Shape {
|
|
@Override
|
|
public void draw() {
|
|
System.out.println("绘制圆形");
|
|
}
|
|
}
|
|
|
|
class Rectangle extends Shape {
|
|
@Override
|
|
public void draw() {
|
|
System.out.println("绘制矩形");
|
|
}
|
|
}
|
|
|
|
public class Shapetest {
|
|
public static void drawShape(Shape s) {
|
|
s.draw();
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
Shape circle = new Circle();
|
|
drawShape(circle);
|
|
|
|
Shape rectangle = new Rectangle();
|
|
drawShape(rectangle);
|
|
|
|
Shape general = new Shape();
|
|
drawShape(general);
|
|
}
|
|
}
|