First, basic knowledge
1, super (parameter): Call a constructor in the base class (should be the first statement in the constructor)
2, this (parameter): Invoke another form of constructor in this class (should be the first statement in the constructor)
3, Super: It refers to members of the immediate parent class of the current object (used to access member data or functions in the parent class that is hidden in the immediate parent class, when the base class has the same member definition as the derived class)
such as: Super. Variable name
Super. member function name (argument)
4, this: it represents the current object name (in the program is easy to produce two semantics, you should use this to indicate the current object; If the member data in the function's form-participation class has the same name, you need this to indicate the member variable name)
Second, application examples
Class Point
{private int x,y;
Public point (int x,int y)
{
This.x=x; This represents the current object name
This.y=y;
}
public void Draw ()
{
}
Public Point ()
{
This (0,0); This (parameter) calls another form of constructor in this class
}
}
Class Circle extends Point
{
private int radius;
Public Circle (int x0,int y0, int R)
{
Super (X0,Y0); Super (parameter) calls one of the constructors in the base class
Radius=r;
}
public void Draw ()
{
Super. Draw (); Super it references members in the immediate parent class of the current object
Drawcircle ();
}}