1, methods in the constructor method of the parent class cannot be called to override the quilt class.
Analysis:
When initializing a subclass, the parent class is initialized first, that is, the constructor method of the parent class is called;
If other methods that can be overridden are called in the constructor of the parent class, then the call is actually the overridden method in that subclass;
So the subclass is not initialized, so it can cause some problems.
The sample code is as follows:
Parent class:
Public class Father1 { public Father1 () { overRide1 (); } Public void OverRide1 () { System.out.println ("Member method of the parent class ...) ........................
Sub-class:
Public classSon1extendsFather1 {Private FinalDate date; PublicSon1 () {Date=NewDate (); } @Override Public voidOverRide1 () {System.out.println (date); } Public Static voidMain (string[] args) {Son1 son1=NewSon1 (); Son1.override1 (); }}
If you run the main method of the subclass, the result of the console output is:
Null
Mon APR 12:55:48 CST 2017
When the parent class is initialized, the OverRide1 method of the subclass is called in the constructor method;
<EffectiveJava> Reading notes--01 The use of inheritance note