当前位置:网站首页>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.
边栏推荐
- 基于OpenVINO工具套件简单实现YOLOv7预训练模型的部署
- Greenplum Database Fault Analysis - Can a Soft Connection Be Made to the Database Base Folder?
- Advanced Numbers_Review_Chapter 1: Functions, Limits, Continuity
- Programmer's list of sheep counting when insomnia | Daily anecdote
- 直播回放含 PPT 下载|基于 Flink & DeepRec 构建 Online Deep Learning
- Introduction to SDC
- iNFTnews | 对体育行业和球迷来说,NFT可以带来什么?
- 常见的硬件延迟
- Greenplum数据库故障分析——版本升级后gpstart -a为何返回失败
- 树表的查找
猜你喜欢
01 [Foreword Basic Use Core Concepts]
Live playback including PPT download | Build Online Deep Learning based on Flink & DeepRec
LPQ (local phase quantization) study notes
从零到一快速学会三子棋
Hypervisor related knowledge points
[ROS] (10) ROS Communication - Service Communication
RAID disk array
Log an error encountered when compiling google gn "I could not find a ".gn" file ..."
[Word] #() error occurs after Word formula is exported to PDF
iNFTnews | 对体育行业和球迷来说,NFT可以带来什么?
随机推荐
Opening - Open a new .NET modern application development experience
matlab绘制用颜色表示模值大小的箭头图
The 2022 EdgeX China Challenge will be grandly opened on August 3
网络安全与元宇宙:找出薄弱环节
使用OpenVINO实现飞桨版PGNet推理程序
树形查找(二叉查找树)
leetcode 15
Greenplum Database Fault Analysis - Why Does gpstart -a Return Failure After Version Upgrade?
leetcode 15
C语言日记 9 if的3种语句
树表的查找
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
"Configuration" is a double-edged sword, it will take you to understand various configuration methods
LeetCode uses the minimum cost to climb the stairs----dp problem
C student management system Insert the student node at the specified location
没有对象的程序员如何过七夕
多线程(2)
学习笔记-----左偏树
Domain Driven Design - MDD
ARM Mailbox