1 / ** 2 * Use super keyword in three ways: 3 * 1, a member of the subclass, the access member variables of the parent class 4 * 2, a member of the subclass, the members of the parent class method access 5 * 3, in the constructor subclass, access to the parent class constructor . 6 * . 7 * and the this super difference . 8 * super keyword is used to access the contents of the parent class, the this keyword is used to access this type of content. 9 * 1, the members of this class the method, accessing the class member variable 10 * 2, class members in the present method, another member of this class access method 11 * 3, in the present class constructor, accessing the class constructor another 12 * in the third usage among Note: 13 is * a, this (...) call must be the first statement of the method of construction, only 14 * B, and this two Super kinds of construction calls can not be used simultaneously. 15 * / 16 public class Zi the extends Fu { . 17 int NUM = 20 is ; 18 is . 19 public Zi () 20 is { 21 is // Super (); // not write, call the default method. 22 is the this (111); // this class constructor with no arguments, this class has a call reference structure 23 is } 24 25 public Zi ( int n-) { 26 is the this (1,2 ); 27 } 28 29 public Zi ( int n- , int m) { 30 31 is } 32 33 is public void methodZi () { 34 is System.out.println ( Super .num); // parent class NUM 35 } 36 37 [ public void Method () 38 is { 39 Super .method (); // parent class 40 System.out.println ( "subclass method" ); 41 is } 42 is 43 is public void shownum () { 44 is int NUM = 10 ; 45 System.out.println ( the this .num); // 20 is 46 is } 47 }
. 1 public class Fu { 2 int NUM = 10 ; . 3 . 4 public void Method () . 5 { . 6 System.out.println ( "parent class method" ); 7 } 8 }