当前位置:网站首页>多态中的向上和向下转型
多态中的向上和向下转型
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("狗刨");
}
}
边栏推荐
- Unexpected exception ... code: Badrequest when downloading Xilinx 2018.2
- Roblox sword nine sword two
- 蓝桥杯——最小框架
- Some examples.
- Check whether tensorflow supports GPU and test program
- Markdown skill tree (9): tables
- Markdown skill tree (5): picture
- ES中配置ext.dic文件不生效的原因
- Use of LSTM neural network and general neural network
- Simulation analysis of sailing dynamics
猜你喜欢

MFC中利用CDockablePane实现悬浮窗

感知健康生活 赋能无界连接 ——为OpenHarmony 3.1生态构建贡献芯海力量

解题-->在线OJ(十三)

Unexpected exception ... code: Badrequest when downloading Xilinx 2018.2

Blue Bridge Cup -- Analysis of the second batch of test questions of the 13th session

Problem solving -- > online OJ (13)

Detailed design of PLC program control system for washing machine

部署Prometheus-server服务 system管理

Wechat applet learning notes (summer vacation)

Interviewer: why does database connection consume resources? Where are the resources consumed?
随机推荐
Blue Bridge Cup - minimum frame
Postman pre request
Software testing
Es query syntax
SYSTEMd management node exporter
Cross domain data request using jsonp
【工控老马】洗衣机PLC程序控制系统设计详解
Two ways to write throttling - recently seen
循环嵌套问题:为什么大循环在内,小循环在外可以提高程序的运行效率
Matlab Simulink simulation and analysis of power grid sweep frequency
Problem solving -- > online OJ (13)
From XX import* is equivalent to from XX import *, and no space is required
KingbbaseES V8R6集群维护案例之---集群之间数据迁移
Kingbasees coping with transaction rollback caused by too fast growth of table age
[industrial control old horse] detailed explanation of design principle of pattern fountain based on PLC
1032 Sharing
Use of LSTM neural network and general neural network
施努卡:轮胎自动抓取安装,3D视觉定位,机器人自动抓取
路由详解(九阳真经)
4 years of working experience, and you can't tell the five communication modes between multithreads. Can you believe it?