super关键字详解1

package test5;
/*super父类中的name,父类中的m1
super是用在子类中还是主函数中?主函数没有继承关系,不能用super,因为并没有父类和子类关系存在,所以只能用在子类中
1、super不是引用类型,super中存储不是内存地址,指向的不是父类对象,super代表的是子类对象中的父类型特征
2、什么时候使用super?
子类和父类都有某个数据,例如子类和父类中都有name这个属性
如果要在子类中访问父类中的name属性,需要使用super
*3、super可以用在什么地方?
* 1可以用在成员方法中
* 2可以用在构造方法中
*/
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("员工在工作");
}
}


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);

}



}

猜你喜欢

转载自blog.csdn.net/rolic_/article/details/80163160