继承时成员函数:
当子父类中出现成员函数一抹一样的情况,会运行子类的函数。
这种现象,称为覆盖操作,这时函数在子父类中的特性。
函数的两个特性:
1:重载。同一个类中参数列表,参数类型不同。overload
2:覆盖。子类中,覆盖称为重写,覆写,override
覆盖(重写)注意事项:
1:静态只能覆盖静态,或被静态覆盖。
2:子类方法覆盖父类方法时,子类的权限必须要大于等于父类权限。
否则编译会出错:
package day02;
public class Person {
String name="fl";
public void show(){
System.out.println(name);
};
}
class Car{
}
class Student extends Person{
//show()此处报错Cannot reduce the visibility of the inherited method from Person
//不能降低从人那里继承的方法的可见性
void show(){
System.out.println(name);
};
}
class Test{
public static void main(String[] args) {
Student student = new Student();
student.show();
}
}
原文:https://www.cnblogs.com/liyunchuan/p/10645286.html