当前位置:网站首页>多态中的向上和向下转型
多态中的向上和向下转型
2022-06-29 06:40:00 【Mertrix_ITCH】
/* * * 多态中的向上转型和向下转型: * * 引用类型之间的转换 * 向上转型 * 由小到大(子类型转换成父类型) * 向下转型 * 由大到小 * 基本数据类型的转换 * 自动类型转换 * 由小到大 * byte short char --- int --- long --- float --- double * 强制类型转换 * 由大到小 * * * */
public class PoymorphicDemo3{
public static void main(String[] args) {
Animal2 a = new Dog();//向上转型
//a.eat();
Dog d = (Dog)a;//向下转型
d.swim();
}
}
class Animal2 {
public void eat() {
System.out.println("吃东西");
}
}
class Dog extends Animal2 {
public void eat() {
System.out.println("啃骨头");
}
public void swim() {
System.out.println("狗刨");
}
}
边栏推荐
- ES中配置ext.dic文件不生效的原因
- [translation] E-Cloud. Large scale CDN using kubeedge
- Alicloud access resource: nosuchkey
- 关于KingbaseES临时文件过大问题
- 道闸控制器通讯协议
- Kingbasees coping with transaction rollback caused by too fast growth of table age
- Roblox sword nine sword two
- Gateway controller communication protocol
- Markdown skill tree (9): tables
- Es query syntax
猜你喜欢
随机推荐
ES中配置ext.dic文件不生效的原因
阿里云访问资源:NoSuchKey
Use of LSTM neural network and general neural network
cv2.cvtColor
How to view software testing training? Do you need training?
【工控老马】基于西门子S7-200PLC的跑马灯控制系统的设计方案详解
并发幂等性防抖
SYSTEMd management node exporter
tf.compat.v1.global_variables
Appium自动化测试基础 — ADB常用命令(三)
KingbaseES 中select distinct on 语句
Appium 环境搭建
tf. count_ nonzero
How to permanently set Mysql to utf8 encoding?
道闸控制器通讯协议
Postman pre request
jmeter 用beanshell导入自己jar包老是查找不到
[translation] E-Cloud. Large scale CDN using kubeedge
Roblox剑九之剑二
Dump (cl\alv\tree\base================================cp|set\items\for\column) when expanding node or clicking toolbar button








