问题其实问太专业我猜应该java初学者吧
按照意思重载了父类该方法时操作子类定义变量
.jackshow.parent;
public class Point {
private String x;
private String y;
/**
* 默认构造函数
*/
public Point(){
}
public String getX() {
return x;
}
public void setX(String x) {
this.x = x;
}
public String getY() {
return y;
}
public void setY(String y) {
this.y = y;
}
}
package net.jackshow.child;
import net.jackshow.parent.Point;
public class Point3D extends Point{
static int c=0;
public Point3D(){
super();
c++;
}
public static void main(String[] args){
Point3D child = new Point3D();
Point3D child1 = new Point3D();
System.out.println("x="+child.getX()+",y="+child.getY()+",c="+c);
}
}
第3,你在class前面加上abstract,接口则把class改为interface,然后变量全部改为public的 |