这是我在Java中的测试程序.我想知道抽象类在这里有多重要,为什么我们为此使用抽象类.
它是强制性的还是最好的方法; 如果是这样的话?
class Shape1 {
int i = 1;
void draw() {
System.out.println("this is shape:" + i);
}
}
class Shape2 {
int i = 4;
void draw() {
System.out.println("this is shape2:" + i);
}
}
class Shape {
public static void main(String args[]) {
Shape1 s1 = new Shape1();
s1.draw();
Shape2 s2 = new Shape2();
s2.draw();
}
}
Run Code Online (Sandbox Code Playgroud)