day09--继承中方法的覆盖重写_概念与特点以及注意事项

This commit is contained in:
xx
2026-09-23 11:22:43 +08:00
parent e2b378cc29
commit 5ed43a5133
2 changed files with 20 additions and 0 deletions
@@ -0,0 +1,14 @@
package com.inmind.extends_method03;
/*
重载(overload) :在同一个类中,方法名相同,参数列表不同(类型,数量,顺序)
重写(override) :在父子类中,方法名相同,参数列表相同
java中的4种权限:public > protected>(default)不写就是默认权限>private
重写的注意事项:
1.子类方法重写父类方法时,必须保证权限大于等于父类的权限
2.private的内容不能继承的,也就不能重写
3.返回值类型,方法名和参数列表保持一致
*/
public class Demo05 {
}
@@ -1,8 +1,14 @@
package com.inmind.extends_method03; package com.inmind.extends_method03;
public class Zi extends Fu{ public class Zi extends Fu{
@Override//该注解,用来验证当前是否是重写
public void method(){
System.out.println("子类的method方法");
}
public void methodZi(){ public void methodZi(){
System.out.println("子类的methodZi方法"); System.out.println("子类的methodZi方法");
} }