当前位置:网站首页>core technology
core technology
2022-07-22 09:25:00 【weixin_ fifty million one hundred and seventy-nine thousand nin】
Inherit keywords :extends, Literally , Subclasses can obtain some methods or variables of the parent class through inheritance . Inherited relationships , It is usually the relationship between classes , Radiation to nature generally refers to , Animals to birds are inherited , Birds inherit some characteristics of animals . From abstract to concrete , Birds to ostriches , It's also an inheritance relationship .
Method rewrite , Subclasses can use some division of the parent class private、final The method of decoration , You can also rewrite what it can use . Rewritten rules : Keep the name of the parent method , Override the contents of the parent method , The range of modifiers is usually larger or equal .
create Test class , Define a method dolt(), Create subclasses Test2, Override parent method dolt()
Object Class is java The parent class of all objects in . Method instanceof Query whether the object belongs to a class , Belong to return true, Instead, return to false. It can also be used. getClass(),getName() Returns the class to which the current object belongs
Upward transformation , Instantiate the subclass object as a variable of the parent object ; Move down , Turn the parent object into a subclass object variable , Because the parent class rotor class is abstract to concrete , therefore , Cast required .
Interface :interface, Interface is a pure abstract class , There is no code body in the defined method . Interfaces don't make much sense , Because his usage lies in inheritance , Subclasses rewrite methods according to their own characteristics , And this method , You can directly define . One interface per class ,implements The usage is and interface Interoperable ,interface Definition implements Then use
polymorphic : stay java In inheritance, multiple subclasses can inherit the same parent , By turning up , It can be implemented in the parent class to replace the child class , Subclasses only need to call objects .
边栏推荐
猜你喜欢
随机推荐
Configure opencv in QT
遇到的问题记录
数学运算
c语言之指针(三)
聊天室项目
Advertisements inserted in solo articles are not displayed
线性代数学习笔记——第二十五讲——向量在轴上的投影
Gradle 15分钟入门教程
Municipalités locales - importations, exportations et balance commerciale (2000 - 2020)
SQL注入
文献: Axure(简单介绍)
OpenGL:freeglut ERROR: Function <glutCreateWindow> called without first calling ‘glutInit‘.
How to create threads
程序员那些年的斗智斗勇!!!
4000+上市公司所属省份、城市、经营等多指标数据已更新至2022.1
h5py快速入门指南
数千万数据量:2000-2019全中国省、市、县企业注册数据经纬度、注册数目等多指标信息
position: -webkit-sticky; /* for Safari */ position: sticky;
高频leetcode深搜部分:剑指 Offer 13. 机器人的运动范围
使用Harry过程中FAQ(问题解答)