class Plate {
  Plate(int i) {
    System.out.println("Plate constructor");
  }
}class DinnerPlate extends Plate {
  DinnerPlate(int i) {
    super(i);
    System.out.println(
      "DinnerPlate constructor");
  }
}class Utensil {
  Utensil(int i) {
    System.out.println("Utensil constructor");
  }
}class Spoon extends Utensil {
  Spoon(int i) {
    super(i);
    System.out.println("Spoon constructor");
  }
}class Fork extends Utensil {
  Fork(int i) {
    super(i);
    System.out.println("Fork constructor");
  }
}class Knife extends Utensil {
  Knife(int i) {
    super(i);
    System.out.println("Knife constructor");
  }
}// A cultural way of doing something:
class Custom {
  Custom(int i) {
    System.out.println("Custom constructor");
  }
}public class PlaceSetting extends Custom {
  Spoon sp;
  Fork frk;
  Knife kn;
  DinnerPlate pl;
  PlaceSetting(int i) {
    super(i + 1);
    sp = new Spoon(i + 2);
    frk = new Fork(i + 3);
    kn = new Knife(i + 4);
    pl = new DinnerPlate(i + 5);
    System.out.println(
      "PlaceSetting constructor");
  }
  public static void main(String[] args) {
    PlaceSetting x = new PlaceSetting(9);
  }
}这是 简单的子类继承父类 但是super的函数里的参数我不知道什么意思 还有在PlaceSetting函数里面super(i + 1);
    sp = new Spoon(i + 2);
    frk = new Fork(i + 3);
    kn = new Knife(i + 4);
    pl = new DinnerPlate(i + 5);什么意思啊?

解决方案 »

  1.   

    super就是调用父类的构造函数,入参自然就是父类构造函数的参数了
      

  2.   

    class Game {
      Game(int i) {
        System.out.println("Game constructor");
      }
    }class BoardGame extends Game {
      BoardGame(int i) {
        super(i);
        System.out.println("BoardGame constructor");
      }
    }public class Chess extends BoardGame {
      Chess() {
        super(11);
        System.out.println("Chess constructor");
      }
      public static void main(String[] args) {
        Chess x = new Chess();
      }
    } 这个我也懂你看这个上面super(11);难道就是为了向父类入参感觉这11一点也没有只是说明他是int型
      

  3.   

    你懂this么,懂了this不懂super啊。。不过这个代码只是传参数而已,参数本身没什么用,Game里的构造方法参数是int的了。。
      

  4.   

    父类的单词是superclass,从单词意思可以猜,super就是指子类的直接父类,super()就是父类的无参构造方法,括号里面有参数则调用有参的父类构造方法,另外也可以通过"super."的形式调用父类的成员变量或函数。。