Detailed explanation of super keyword 1

package test5;
/*super name in the parent class, m1
super in the parent class is used in the subclass or the main function?
The main function has no inheritance relationship, so super can not be used, because there is no relationship between parent and subclass, so it can only be used in subclasses super represents the supertype characteristic in the subclass object
2. When to use super?
Both the subclass and the superclass have certain data, for example, the subclass and the superclass have the attribute name.
If you want to access the name attribute in the superclass in the subclass, you need to use super
*3, where can super be used?
* 1 can be used in member methods
* 2 can be used in constructors
*/
public class test5 {


public static void main(String[] args) {
manager m=new manager();
m.m1();
}


}


class employee{
String name = "pi"; public void m1(){ System.out.println("Employee is working"); } }







class manager extends employee{
String name ="pai"; public void m1() { System.out.println("经理在工作"); super.m1(); System.out.println(name); System.out.println(this.name); System.out.println(super.name); } }













Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325982329&siteId=291194637