Whether Constructor constructor can be override

Constructor constructor can not be inherited, and therefore can not rewrite Override, but can be overloaded Overload.

Constructor can not be inherited, so it can not be Constructor override. Every class must have its own constructor, responsible for building this part of the structure of their own. Subclass does not override the parent class constructor, but instead must be responsible for calling the parent class constructor in the beginning.

First, the constructor is used to do? (What)

 构造器是用来生成一个类的实例是用来初始化这个实例用的

Second, how constructors work? (How)

 Java在构造实例时的顺序是这样的:

1, the space assignment, and the members of the object or an empty initialized to 0, java does not allow a user to manipulate objects of indefinite value.

2, execution attribute values ​​explicitly initialized

3, the implementation of the constructor

4, the variable associated with the object in the heap

And there is the step of performing constructor can be divided into the following steps:

1, Bind constructor parameter

2, if this call explicitly, then recursive calls this constructor then skip to step 5

3, the recursive call, either explicitly or implicitly parent class constructor, in addition to the Object, since it has no parent

4, an explicit instance variable is initialized (i.e. the upper side in the second step of the process is performed after the call returns,

This step corresponds to implicitly performed after executing the parent structure, it looks like a special treatment)

Third, the configuration is not available orerride (why)

In fact, you only need to remember one sentence: not the constructor method, the method used to modify the characteristics of all modifiers can not be used to modify the constructor (the constructor does not mean

With these characteristics, although it is not modified with static constructor, but it has a static characteristic) constructor can only use this public private protected

Three permissions modifier, and can not have a return statement.

Guess you like

Origin blog.csdn.net/weixin_44517301/article/details/93161988