java-重写

重写有要求

1. 方法名:必须和父类被重写的方法名相同
2. 形参列表:必须和父类被重写的方法名相同
3. 返回值类型:
    A. 基本数据类型和void:要求与父类被重写的返回值数据类型一致
    B. 引用数据类型:要求子类重写的方法返回值类型 <= 父类被重写的方法的返回值类型
        ## 例如:子类方法的返回值类型是Student,父类被重写的方法的返回值类型Student
                子类方法的返回值类型是Student,父类被重写的方法的返回值类型是Person
                子类方法的返回值类型是Person,父类被重写的方法的返回值类型是Student(这个是错误的)
4. 修饰符
    A. 权限修饰符:子类重写方法的权限修饰符的可见范围 >= 父类被重写的权限修饰符的可见范围
    B. 其他修饰符:
When nothing seems to help, I go look at a stonecutter hammering away at his rock, perhaps a hundred times without as much as a crack showing in it. Yet at the hundred and first blow it will split in two, and I know it was not that blow that did it, but all that had gone before. -- Jacob Riis
原文地址:https://www.cnblogs.com/xhwy-1234/p/12377942.html