摘要:中的抽象类代码实现通过键盘来打电话通过键盘来打短信通过语音来打电话通过语音来发短信运行
java中的抽象类 代码实现
Telphone.java
package com.imooc;
public abstract class Telphone {
public abstract void call();
public abstract void message();
}
/javaDemo5/src/com/imooc/CellPhone.java
package com.imooc;
public class CellPhone extends Telphone {
public void call() {
// TODO Auto-generated method stub
System.out.println("通过键盘来打电话");
}
public void message() {
// TODO Auto-generated method stub
System.out.println("通过键盘来打短信");
}
}
SmartPhone.java
package com.imooc;
public class SmartPhone extends Telphone {
public void call() {
// TODO Auto-generated method stub
System.out.println("通过语音来打电话");
}
public void message() {
// TODO Auto-generated method stub
System.out.println("通过语音来发短信");
}
}
/javaDemo5/src/com/imooc/Initail.java
package com.imooc;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
Telphone tel1 = new CellPhone();
tel1.call();
tel1.message();
Telphone tel2 = new SmartPhone();
tel2.call();
tel2.message();
}
}
运行
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/73173.html
摘要:中的多态引用的多态父类的引用是可以指向子类对象报错方法多态动物具有吃的能力狗具有吃肉的能力狗具有看门的能力父类的引用是可以指向子类对象报错 java中的多态 showImg(https://segmentfault.com/img/bVbnDYA?w=1138&h=612); showImg(https://segmentfault.com/img/bVbnD6B?w=344&h=17...
摘要:多态中的引用类型转换代码自动类型提升,向上类型转换向下类型转换强制类型转型无法进行类型转换 多态中的引用类型转换 showImg(https://segmentfault.com/img/bVbnEal?w=1166&h=597); showImg(https://segmentfault.com/img/bVbnEaq?w=1178&h=606); 代码 /javaDemo4/src...
摘要:中的接口实例智能手机和都有玩游戏的功能代码具有玩游玩的功能具有玩游玩的功能 java中的接口 showImg(https://segmentfault.com/img/bVbnEzV?w=1194&h=621); showImg(https://segmentfault.com/img/bVbnEzX?w=1192&h=615); showImg(https://segmentfaul...
摘要:人类说话中国人说汉语,美国人说英语继承实现人类具有说话的能力中国人说汉语美国人说英语抽象类实现中国人说汉语美国人说英语 人类说话,中国人说汉语,美国人说英语 showImg(https://segmentfault.com/img/bVbnFaM?w=305&h=188); 继承实现 /javaDemo6/src/com/imooc/Person.java package com.im...
摘要:中的继承初始化顺序父类和子类年龄动物可以吃东西类执行了年龄狗可以吃东西类执行了对象的属性和构造方法年龄动物可以吃东西类执行了的 java中的继承初始化顺序 showImg(https://segmentfault.com/img/bVbnBI1?w=1277&h=671); showImg(https://segmentfault.com/img/bVbnBKG?w=811&h=427...
阅读 1166·2021-09-27 13:36
阅读 1655·2021-09-08 09:35
阅读 1336·2021-08-12 13:25
阅读 1664·2019-08-29 16:52
阅读 3215·2019-08-29 15:12
阅读 2968·2019-08-29 14:17
阅读 2860·2019-08-26 13:57
阅读 1253·2019-08-26 13:51