当前位置:网站首页>Access Characteristics of Constructor under Inheritance Relationship
Access Characteristics of Constructor under Inheritance Relationship
2022-08-05 02:26:00 【Friday.T】
Table of Contents
Foreword
First of all, let's understand the basic concept of inheritance. Inheritance describes the relationship between things. Through inheritance, a relationship system can be formed between various things. In JAVA, class inheritance refers to aOn the basis of the existing class, build a new bit, the constructed mind is called the subclass, the existing class is called the parent class, and the subclass inherits the properties and methods of the parent class, so that the subclass object has the characteristics andBehavior.The format is as follows:
class parent class{....}class subclass extends superclass{....}
one, super keyword
When the subclass overrides the method of the parent class and the subclass object will not be able to access the overridden method of the parent class, in order to solve this problem, the super keyword provided by JAVA, the super keyword can call the parent class in this classThe common attribute method and construction method of , the specific usage of the super keyword is explained in detail below:
(1) Use the super keyword to access the member variables and methods of the parent class
super.member variablessuper.member method(parameter 1, parameter 2...)
(2) Use the super keyword to access the constructor specified in the parent class
super(parameter1, parameter2..)
II. Access features
(1) In the constructor of the subclass, if a super(); is not displayed, one will be given by default, and if one is displayed, it will not be given.
Pay attention to the code of the above two pictures. In the second picture, we wrote a super(), which is the same as the first one without writing. It can be proved that if there is no writing displayed, thenOne will be given by default. If one is displayed, it will not be given again.
(2) super (parameter), must be the first statement, otherwise an error will be reported. When creating a subclass object, the subclass will definitely call a constructor of the parent class. If there are no parameters, the default call will be no parameters.Constructor, if there are parameters, call the parameterized constructor.
Three, this keyword
Common usage:
this.member variables of this class
this.member method of this class
this(parameter)
(1) Access the attribute in this class, if this class does not have this attribute, look it up from the parent class.
(2) Access the method in this class, if this class does not have this method, look it up from the parent class.
(3) must be written in the first line of the constructor (so super() this() cannot exist at the same time).
(4) Only other constructors of this class can be called, not themselves (that is, they cannot be called recursively, and the constructor itself cannot be called directly or indirectly through this in a constructor).
Summary
The above is my access to the construction method under the inheritance relationship. It mainly introduces the two keywords super and this, as well as some special usage methods and precautions. There are still many shortcomings in the article, I hope you will point out.
边栏推荐
- 英特尔 XDC 2022 精彩回顾:共建开放生态,释放“基建”潜能
- Understand the recommendation system in one article: Recall 06: Two-tower model - model structure, training method, the recall model is a late fusion feature, and the sorting model is an early fusion
- iNFTnews | 对体育行业和球迷来说,NFT可以带来什么?
- C语言日记 9 if的3种语句
- SuperMap iDesktop.Net之布尔运算求交——修复含拓扑错误复杂模型
- PHP技能评测
- 基于OpenVINO工具套件简单实现YOLOv7预训练模型的部署
- matlab绘制用颜色表示模值大小的箭头图
- LPQ (local phase quantization) study notes
- 使用OpenVINO实现飞桨版PGNet推理程序
猜你喜欢
Understand the recommendation system in one article: Recall 06: Two-tower model - model structure, training method, the recall model is a late fusion feature, and the sorting model is an early fusion
C language diary 9 3 kinds of statements of if
DAY22: sqli-labs shooting range clearance wp (Less01~~Less20)
The 2022 EdgeX China Challenge will be grandly opened on August 3
线性表的查找
MySQL learning
【MySQL系列】- LIKE查询 以%开头一定会让索引失效吗
matlab绘制用颜色表示模值大小的箭头图
“嘀哩哩,等灯等灯”,工厂安全生产的提示音
LeetCode使用最小花费爬楼梯----dp问题
随机推荐
iNFTnews | 对体育行业和球迷来说,NFT可以带来什么?
Log an error encountered when compiling google gn "I could not find a ".gn" file ..."
力扣-相同的树
nodeJs--encapsulate routing
Quickly learn chess from zero to one
力扣-二叉树的前序遍历、中序遍历、后序遍历
Common hardware delays
01 [Foreword Basic Use Core Concepts]
浅谈数据安全治理与隐私计算
【genius_platform软件平台开发】第七十六讲:vs预处理器定义的牛逼写法!!!!(其他组牛逼conding人员告知这么配置来取消宏定义)
【OpenCV 图像处理2】:OpenCV 基础知识
编译预处理等细节
迁移学习——Distant Domain Transfer Learning
mysql树状结构查询问题
Programmer's list of sheep counting when insomnia | Daily anecdote
DAY22:sqli-labs 靶场通关wp(Less01~~Less20)
How to deal with your own shame
js中try...catch和finally的用法
[LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)
[Endnote] Word inserts a custom form of Endnote document format