当前位置:网站首页>Object,多态 1(第八天)
Object,多态 1(第八天)
2022-07-31 05:10:00 【不习惯有你】
Object
A.object是所有类的父类
一个类如果没有使用extends显性的继承另外一个类那么这个类就继承自object类
B.object类的主要方法
1.toString()方法
equals与==
equals比较的是值,==比较的是地址
多态:
对应同一个指令(调用同一个名称的方法),不同的对象给予的反应(不同的方法实现)
规范(多态实现的前提):
1.必须要有继承关系
2.子类方法必须重写父类的方法
3.父类引用指向子类对象
如何实现多态:
-编写父类
-编写子类,子类重写父类方法
-运行时,使用父类的类型,子类的对象
多态的目的:
为了提高代码的扩展性和维护性
方便代码逻辑的编写
多态两种表现形式
1.父类作为方法的参数
2.父类作为方法的返回值类型
引用类型的转换跟基本数据类型的转换类似:
当父类需要转换成子类的时候,要进行强制转换,但在强制转换之前一定要先判断父类引用指向的子类对象到底是谁,如果无法确定,在运行过程中可能出错
instanceof运算符
对象 instanceof类或接口
instanceof通常和强制类型转换结合使用
边栏推荐
猜你喜欢
随机推荐
Why use Flink and how to get started with Flink?
Sword Point Offer Special Assault Edition ---- Day 1
Input length must be multiple of 8 when decrypting with padded cipher
Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
闭包(二)
Refinement of the four major collection frameworks: Summary of List core knowledge
a different object with the same identifier value was already associated with the session
剑指offer基础版 ----- 第25天
gin框架学习-Gin框架和Gorm框架搭建一个简单的API微服务
1D, 2D, 3D convolution operations in pytorch
The interviewer asked me how to divide the database and the table?Fortunately, I summed up a set of eight-part essays
Proteus 8 Professional安装教程
Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
Interviewer, don't ask me to shake hands three times and wave four times again
wpf wrapPanel居中并从左到右排列
对list集合进行分页,并将数据显示在页面中
剑指offer基础版 --- 第21天
Element concatenation operations in numpy and pytorch: stack, concatenat, cat
tf.keras.utils.pad_sequences()
再见了繁琐的Excel,掌握数据分析处理技术就靠它了








