class Car
{
class Wheel
{
}
}class PlaneWheel extends Car.Wheel
{
PlaneWheel(Car car)
{
car.super();               // 这句怎么理解?调用 car 的父类构造函数? 调用Object 构造函数?!
}
public static void main(String[] args)
{
Car car=new Car();
PlaneWheel pw=new PlaneWheel(car);

}
}

解决方案 »

  1.   

    super:调用父类具有相同形参的构造函数
      

  2.   

    调用Object 构造函数吗?!以前写类构造函数都没这么写。
      

  3.   


    调用Car.Wheel的构造函数
    只能且必须用car.super(),而不能用super(),或忽略不写。
      

  4.   

    对呀,那父类是什么?Object吗?那平时写类的构造方法都没写调用父类 Objectd的语句。
      

  5.   


    greathawker() ( ) 信誉:100    Blog   加为好友  2007-5-11 16:26:07  得分: 0  
    调用Car.Wheel的构造函数
    只能且必须用car.super(),而不能用super(),或忽略不写。**************************************************
    刚做了测试,确实调用Car.Wheel的构造函数,但难以理解。
      

  6.   

    被你们搞得晕头转向了,好像java 版没有像.net版的孟子E章那种高手兼热心人啊.
      

  7.   

    刚想了一下,其实上面的人说测试是不行的.
    Car.Wheel
    这个内部类是被继承的,他的构造器调用是肯定会在PlaneWheel构造器调用之前就开始调用.可以参考Thinking in java第7章的多态,里面有构造器的调用顺序.greathawker
    调用Car.Wheel的构造函数
    只能且必须用car.super(),而不能用super(),或忽略不写。我用Eclipe调式了一下,鉴定是调用的Car.Wheel
      

  8.   

    class Car
    {
    public Car(){

    System.out.println("Car");
    }

    class Wheel{
    public Wheel(){
    System.out.println("Wheel");
    }
    }
    }public class PlaneWheel extends Car.Wheel{
    PlaneWheel(Car car){
    car.super(); 
    System.out.println("PlaneWheel");
    }

    public static void main(String[] args){

    Car car=new Car();

    PlaneWheel pw=new PlaneWheel(car);
    }


    }------------------------
    结果:
    Car
    Wheel
    PlaneWheel
      

  9.   

    我个人把super就当成调用父类了!
    哪个参数调用,直接找到其父类就好了
      

  10.   

    java中让人摸不透的东西之一.
    为什么这里是用super而不是用child
      

  11.   

    class Car
    {
    public Car(){

    System.out.println("Car");
    }

    class Wheel{
    public Wheel(){
    System.out.println("Wheel");
    }
    }
    }public class PlaneWheel extends Car.Wheel{
    PlaneWheel(Car car){
    car.super(); 
    System.out.println("PlaneWheel");
    }

    public static void main(String[] args){

    Car car=new Car();

    PlaneWheel pw=new PlaneWheel(car);
    }


    }------------------------
    结果:
    Car
    Wheel
    PlaneWheel这样测试是不行的....没看偶说的么...构造器有个调用循序的问题....他一定会执行父类的构造器的..
      

  12.   

    我有thinking in java的电子版本..正好copy给你看..Inheriting from inner classesBecause the inner class constructor must attach to a reference of the
    enclosing class object, things are slightly complicated when you inherit
    from an inner class. The problem is that the “secret” reference to the
    enclosing class object must be initialized, and yet in the derived class
    there’s no longer a default object to attach to. The answer is to use a
    syntax provided to make the association explicit: //: c08:InheritInner.java
    // Inheriting an inner class.
    class WithInner {
    class Inner {}
    }
    public class InheritInner extends WithInner.Inner {
    //! InheritInner() {} // Won't compile
    InheritInner(WithInner wi) {
    wi.super();
    }
    public static void main(String[] args) {
    WithInner wi = new WithInner();
    InheritInner ii = new InheritInner(wi);
    }
    } ///:~
    You can see that InheritInner is extending only the inner class, not the
    outer one. But when it comes time to create a constructor, the default one
    is no good and you can’t just pass a reference to an enclosing object. In
    addition, you must use the syntax FeedbackenclosingClassReference.super();inside the constructor. This provides the necessary reference and the
    program will then compile.其实这段我自己都还没看到,我正好看到这章,看了下目录有讲这个的...就copy来咯.