这是我的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();
}
}