class Po
{
double i,j;
public Po(){
i=0;j=0;
}
public Po(int i,int j){
this.i=i;
this.j=j;
}
public Po(double i,double j){
this.i=i;
this.j=j;
}
};
class Pop extends Po
{
int color;
public void GivePop(double x,double y,int color){
super(x,y);
this.color=color;
}
}
public class Example13
{
public static void main(String args[]){ Pop xu=new Pop();
xu.GivePop(1.2,2.3,2);
System.out.println(xu.color);
}
};
谁能告诉我super 这句怎么错了
我用的是第一句啊!
谢谢了
超级简单的大家帮忙看看吧

解决方案 »

  1.   

    只有在子类的构造方法里才能调用父类的构造方法
    改为:
    class Po
    {
    double i,j;
    public Po(){
    i=0;j=0;
    }
    public Po(int i,int j){
    this.i=i;
    this.j=j;
    }
    public Po(double i,double j){
    this.i=i;
    this.j=j;
    }
    };
    class Pop extends Po
    {
    int color;
    public  Pop(double x,double y,int color){
    super(x,y);
    this.color=color;
    }
    }
    public class Example13
    {
    public static void main(String args[]){ Pop xu=new Pop(1.2,2.3,2); System.out.println(xu.color);
    }
    };
      

  2.   

    super是调用父类的构造方法,而你父类构造方法没有(x,y)参数啊,所以出错
      

  3.   

    xu is the parent class .
    So it isn't include 'color'.