This and super use
One, this use:
One is to reference implicit arguments, and the other is to invoke other constructors of that class. second, super use:
One is to call the superclass method, the other is to call the superclass constructor three, use examples
Package COM.TEST.XQH;
public class Manage extends Employee {private String sex;
Public Manage (string name, int age, String sex) {Super (name, age);//Super Use 2, call superclass constructor this.setsex (sex); Public String GetName () {return super.getname () + "HHHH";//Super Use 1, calling superclass method} public void Setsex (String sex)
{this.sex = sex;
Public String Getsex () {return sex;
public void Say () {SYSTEM.OUT.PRINTLN ("* *");
public static void Main (string[] args) {employee[] e = new employee[2];
E[0] = new Employee ("John", 22);
E[1] = new Manage ("Dick", 22, "male");
System.out.println (E[0].getname ());
System.out.println (E[1].getname ());
Class Employee {private String name;
private int age; Public Employee (String name, int age) {this ();//This use 2, invoke the constructor of the class (this example is the default constructor) THIS.name = name;//This use 1, reference implicit parameter T His.age = age;
This purpose 1 refers to the implicit parameter} public Employee () {} public String GetName () {return name; public void SetName (String name) {thIs.name = name;
public int getage () {return age;
public void Setage (int age) {this.age = age; }
}