当前位置:网站首页>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.
边栏推荐
- [Word] #() error occurs after Word formula is exported to PDF
- 使用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
- 02 [Development Server Resource Module]
- select tag custom style
- matlab绘制用颜色表示模值大小的箭头图
- C student management system Insert the student node at the specified location
- 2022了你还不会『低代码』?数据科学也能玩转Low-Code啦!
- Greenplum Database Fault Analysis - Can a Soft Connection Be Made to the Database Base Folder?
- C学生管理系统 据学号查找学生节点
猜你喜欢

【解密】OpenSea免费创造的NFT都没上链竟能出现在我的钱包里?

.Net C# Console Create a window using Win32 API

ExcelPatternTool: Excel table-database mutual import tool

继承关系下构造方法的访问特点

线性表的查找

select 标签自定义样式
![Chapter 09 Use of Performance Analysis Tools [2. Index and Tuning] [MySQL Advanced]](/img/e7/61863c356e4c7bb03ba27865ee7be0.png)
Chapter 09 Use of Performance Analysis Tools [2. Index and Tuning] [MySQL Advanced]

基于OpenVINO工具套件简单实现YOLOv7预训练模型的部署

优化Feed流遭遇拦路虎,是谁帮百度打破了“内存墙”?
![[Endnote] Word inserts a custom form of Endnote document format](/img/70/e8a6f15b80e9c53db369fd715e51df.png)
[Endnote] Word inserts a custom form of Endnote document format
随机推荐
如何逐步执行数据风险评估
J9数字货币论:web3的创作者经济是什么?
Advanced Numbers_Review_Chapter 1: Functions, Limits, Continuity
回顾51单片机
Leetcode brushing questions - 22. Bracket generation
如何模拟后台API调用场景,很细!
协作D2D局部模型聚合的半分散联合学习
【C语言】详解栈和队列(定义、销毁、数据的操作)
.Net C# Console Create a window using Win32 API
Residential water problems
Chapter 09 Use of Performance Analysis Tools [2. Index and Tuning] [MySQL Advanced]
“嘀哩哩,等灯等灯”,工厂安全生产的提示音
浅谈数据安全治理与隐私计算
Amazon Cloud Technology joins hands with Thundersoft to build an AIoT platform for industry customers
如何看待自己的羞愧感
【LeetCode刷题】-数之和专题(待补充更多题目)
Quickly learn chess from zero to one
开篇-开启全新的.NET现代应用开发体验
select 标签自定义样式
继承关系下构造方法的访问特点