当前位置:网站首页>2021-05-11instanceof和类型转换
2021-05-11instanceof和类型转换
2022-06-23 09:54:00 【鹿其其鹿】
public class Application {
public static void main(String[]args){
Object object = new Student();
System.out.println(object instanceof Student);
System.out.println(object instanceof Person);
System.out.println(object instanceof Object);
System.out.println(object instanceof Teacher);
System.out.println(object instanceof String);
//类型之间的转换:父 子
//高 低
Person obj = new Student();
//student将这个对象转换为Student类型,我们就可以使用Student类型的方法了
Student student = (Student) obj;
student.go();
//==((Student)obj).go();
//子类转换为父类,可能丢失自己本来的一些方法
Student student1 = new Student();
student.go();
Person person = student1;
}
}
- 父类引用指向父类的对象
- 把子类转换为父类,向上转型
- 把父类转换为子类,向下转型:强制转换
- 方便方法的调用,减少重复的代码,简洁
- 抽象:封装 继承 多态
边栏推荐
- Gesture recognition based on mediapipe
- 正则表达式
- 汇编语言中断及外部设备操作篇--06
- ICLR 2022 | 视频中的动态卷积TAdaConv以及高效的卷积视频理解模型TAdaConvNeXt
- Go 单元测试
- J. Med. Chem. | Release: a new drug design model for deep learning based on target structure
- I have been promoted. How can I get along with my former colleagues at the same level?
- RT thread add MSH command
- J. Med. Chem. | RELATION: 一种基于靶标结构的深度学习全新药物设计模型
- 【CTF】 2018_ rop
猜你喜欢

Use Base64 to show pictures
![[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist](/img/1f/dde52dc63de58d67f51161e318a9fb.png)
[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist

xml相关面试题

汇编语言中断及外部设备操作篇--06

什么是BFC?BFC可以解决什么问题

AI system frontier dynamics issue 38: Google has abandoned tensorflow?; Four GPU parallel strategies for training large models; Father of llvm: modular design determines AI future

sql编写问题,求出当月和上月的环比值

数学分析_笔记_第2章:实数与复数
![[geek challenge 2019] hardsql](/img/73/ebfb410296b8e950c9ac0cf00adc17.png)
[geek challenge 2019] hardsql

必须知道的RPC内核细节(值得收藏)!!!
随机推荐
高性能算力中心 — RDMA — 实现技术
XML related interview questions
sql根据比较日期新建字段
Chain implementation of stack -- linear structure
Developer, you may have some misunderstandings about cloud computing
How should junior programmers who enter a small company improve themselves?
beanstalk 常用方法、说明
The usage of lambda of C
map的下标操作符
NIO例子
【CTF】 2018_ rop
Set the CPU to have 16 address lines and 8 data lines, and use mreq as the access control line number Connection between memory and CPU
快速排序的简单理解
文件IO(1)
NiO example
Go string comparison
Jump game of leetcode topic analysis
AI系统前沿动态第38期:谷歌已放弃TensorFlow?;训练大模型的四种GPU并行策略;LLVM之父:模块化设计决定AI前途
RGB and CMYK color modes
[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist