日期:2014-05-20  浏览次数:20642 次

java,错误不知道怎么弄~
public class Overlay 
{
  public static void main(String args[])
  {
  int height=10;
  Rectangle tt=new Rectangle();
  tt.y=height;
  tt.measure();
  tt.print();}
}
class Shap
 {
  public Shap(int y) {
  count = y;
  }

  public int getCount() {
  return count;
  }
  private int count;
  public void measure(){
  System.out.println("super_y="+y);}
  void print(){
  System.out.println("这是Shap的构造函数");}
  }

class Rectangle extends Shap
{
  public Rectangle(int y)
  {
  super(y);
  }
  public void measure()
  {
  super.measure();
  System.out.println("super_y="+y);
  }

}

错误.....不知道怎么改~


------解决方案--------------------
基本概念没清楚,需要系统看书!!
------解决方案--------------------
慢慢来
------解决方案--------------------
super关键字必须放在构造函数的第一句。
------解决方案--------------------
up
------解决方案--------------------
错的也太基础

Rectangle tt=new Rectangle(); //构造法需要参数

tt.y=height; //Rectangle类里没有y这个成员变量

System.out.println( "super_y= "+y);//y是局部变量,不能在另一个方法里调用
------解决方案--------------------
把y提到外面应该就没问题