day09--继承中方法的覆盖重写_应用场景

This commit is contained in:
xx
2026-09-23 11:52:26 +08:00
parent 5ed43a5133
commit d6274e5f4f
3 changed files with 57 additions and 0 deletions
@@ -0,0 +1,16 @@
package com.inmind.extends_method03;
public class NewPhone extends Phone{
//重写来电显示功能 ctrl+o
@Override
public void show() {
super.show();//沿袭父类的功能
//可以对父类的show方法进行扩展
//System.out.println("新的显示电话号码");
System.out.println("显示头像");
System.out.println("备注名称");
System.out.println("显示电诈");
}
}
@@ -0,0 +1,15 @@
package com.inmind.extends_method03;
public class Phone {
public void call(){
System.out.println("打电话");
}
public void send(){
System.out.println("发短信");
}
public void show(){
System.out.println("显示电话号码");
}
}
@@ -0,0 +1,26 @@
package com.inmind.extends_method03;
/*
使用继承的语法,定义2个类,并实现一些功能
1.定义一个10年前的手机类 Phone
2.定义一个现在的手机类 NewPhone
3.10年新旧手机是否有相同的属性,如果有,请用继承来封装到父类中
4.考虑新旧手机是否有不同的功能,如果有,请定义不同的功能方法,是否有相同的功能,也定义出来
打电话
发短信
玩抖音
玩APP
重写的作用:对父类的功能,不满意,那就重写即可,可以选择性地沿袭或扩展
*/
public class Test06 {
public static void main(String[] args) {
Phone phone = new Phone();
NewPhone newPhone = new NewPhone();
phone.show();
newPhone.show();
}
}