One import Constructor rule

来源:互联网 发布:电信智能网络机顶盒 编辑:程序博客网 时间:2024/05/29 17:57

 If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the super class does not have a no-argument constructor, you will get a compile-time error.Object does have such a constructor, so if Object is the only superclass, there is no problem.

 

If a subclass constructor invokes a constructor of its superclass, either explicitly or implicitly, you might think that there will be a whole chain of constructors called, all the way back to the constructor ofObject. In fact, this is the case. It is called constructor chaining, and you need to be aware of it when there is a long line of class descent.