Calling an overridden method from a constructor

后端 未结 4 1185
醉话见心
醉话见心 2021-02-15 09:55

In the following example:

class Base {    
    int  x=10;  

    Base() {    
      show();
    }  

    void show() {   
        System.out.print (\"Base Show \         


        
4条回答
  •  北荒
    北荒 (楼主)
    2021-02-15 10:07

    constructor chaining it makes sense to explain exactly what that is. A subclass constructor method's first task is to call its superclass' constructor method. This ensures that the creation of the subclass object starts with the initialization of the classes above it in the inheritance chain.

    http://java.about.com/b/2009/02/07/java-term-of-the-week-constructor-chaining.htm

    http://javahours.blogspot.com/2008/12/constructor-chain.html

提交回复
热议问题