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.   

    super虽然用在第一行
    但GivePop不是构造函数啊
    super必须是构造函数中第一个语句
      

  2.   

    只能在子类的构造方法里调用父类的构造方法
    改为:
    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);
    }
    }