Override 重写,即子类重新声明了父类中的某个方法,以提供特定于自身的实现。
例如:
public class Animal{
public void eat(){
System.out.println(“Generic Eat Method”);
}
子类的override以下几种是无效的:
1. private void eat() 降低了eat方法的访问权限
2. public void eat() throws IOException 声明的异常超出了被重写的方法的异常声明
3. public void eat(String food) 重写的方法的参数与被重写的不一致
4. public String eat() 方法返回类型与被重写的方法不一致;