当前位置:网站首页>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;
}
}
- 父类引用指向父类的对象
- 把子类转换为父类,向上转型
- 把父类转换为子类,向下转型:强制转换
- 方便方法的调用,减少重复的代码,简洁
- 抽象:封装 继承 多态
边栏推荐
猜你喜欢
![[MRCTF2020]Ez_ bypass](/img/cd/bd6fe5dfc3f1942a9959a9dab9e7e0.png)
[MRCTF2020]Ez_ bypass

必须知道的RPC内核细节(值得收藏)!!!

UEFI source code learning 3.7 - norflashdxe

J. Med. Chem. | Release: a new drug design model for deep learning based on target structure
![[GXYCTF2019]BabySQli](/img/51/a866a170dd6c0160ce98d553333624.png)
[GXYCTF2019]BabySQli

Fill the pit for repvgg? In fact, it is the repoptimizer open source of repvgg2
![[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

Mysql database introduction summary

AI系统前沿动态第38期:谷歌已放弃TensorFlow?;训练大模型的四种GPU并行策略;LLVM之父:模块化设计决定AI前途

Install the typescript environment and enable vscode to automatically monitor the compiled TS file as a JS file
随机推荐
基于STM32设计的宠物投喂器
AI: the Elephant in Room
Subscript operator of map
Lying trough, the most amazing paper artifact!
Centre de calcul haute performance - nvme / nvme - of - nvme - of overview
Is there anyone who plans to open source an industrial "seckill" system architecture?
Tencent tangdaosheng: practice "science and technology for the good" and promote sustainable social value innovation
The second Tencent light · public welfare innovation challenge was launched, and the three competition topics focused on the social value of sustainable development
Fill the pit for repvgg? In fact, it is the repoptimizer open source of repvgg2
RT thread add MSH command
云原生数据库-Amazon RDS
数学分析_笔记_第2章:实数与复数
快速排序的简单理解
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
给RepVGG填坑?其实是RepVGG2的RepOptimizer开源
[geek Challenge 2019] hardsql
NIO例子
Gorm advanced query
高性能算力中心 — NVMe/NVMe-oF — NVMe-oF Overview
Go 单元测试