在java中,实现继承时,为什么在子类的构造函数中,要使用super()调用父类构造函数?
Point(inta,intb){setPoint(a,b);}publicvoidsetPoint(inta,intb){x=a;y=b;}}classLineexte...
Point(int a, int b) {
setPoint(a, b);
}
public void setPoint(int a, int b) {
x=a;
y=b;
}
}
class Line extends Point {
protected int x, y;
Line(int a, int b) {
super(a, b);
}
这样使用怎么错了?
class Line extends Point {
protected int x, y;
Line(int a, int b) {
x = a;
y = b;
} 展开
setPoint(a, b);
}
public void setPoint(int a, int b) {
x=a;
y=b;
}
}
class Line extends Point {
protected int x, y;
Line(int a, int b) {
super(a, b);
}
这样使用怎么错了?
class Line extends Point {
protected int x, y;
Line(int a, int b) {
x = a;
y = b;
} 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询