When Java instantiates an object, if super () is not explicitly used (), the system first calls the non-argument constructor of the parent class (not the one corresponding to the number of self-constructed function parameters) and then calls the constructor of the subclass. If the parent class is not an object class, the super () can only be used in the first row of the constructor. It is invalid in other places. Generally, the constructor does not need to write super (), however, when a class has multiple constructor functions, it is often necessary to explicitly call Super () for ease of understanding ().
The running result of the following sample code is:
I am Father
I am Son: Baidu
I am Father
I am Son
Sample Code:
1. Public class test {
2. Public static void main (string [] ARGs ){
3. New son ("Baidu ");
4. New son ();
5 .}
6 .}
7.
8. Class farther {
9. Public farther (){
10. system. Out. println ("I am Father ");
11 .}
12.
13. Public farther (string name ){
14. system. Out. println ("I AM FATHER:" + name );
15 .}
16 .}
17.
18. Class son extends farther {
19. Public son (){
20. system. Out. println ("I am Son ");
21 .}
22. Public son (string name ){
23. // super ("google ");
24. system. Out. println ("I am Son:" + name );
25 .}
26 .}