当前位置:网站首页>super_ Subclass object memory structure_ Inheritance tree traceability
super_ Subclass object memory structure_ Inheritance tree traceability
2022-07-04 03:18:00 【hv102】
- super( Super )“ Can be seen as ” Is a reference to a direct parent object . Can pass super To access methods and properties in the parent class that are overridden by subclasses .
- Use super To call ordinary methods , Statement has no restricted position , It can be used casually in subclasses .
- In a class , If the first sentence of the constructor is not called super(...) perhaps this(...); that Java By default super(), The meaning is to call the parameterless method of the parent class .
super Use of keywords :
public class TestSuper1 {
public static void main(String[] args) {
new ChildClass().f();
}
}
class FatherClass{
public int value;
public void f(){
value = 100;
System.out.println("FatherClass.value=" + value);
}
}
class ChildClass extends FatherClass{
public int value;
public int age;
public void f(){
super.f();// Call the normal method of the parent class
value = 200;
System.out.println("ChildClass.value=" + value);
System.out.println(value);
System.out.println(super.value);// Call member variable of parent class
}
public void f2(){
System.out.println(age);
}
}
Inheritance tree tracing :
attribute / Method search order :( For example, find variables h)
- Find out if there are any properties in the current class h
- Backtrack each parent in turn , See if there is... In each parent class h, until Object
- If not found , A compilation error appears .
- The above steps , Just find h Variable , Then the process stops .
Constructor call order :
The first sentence is always :super(...) To call the constructor corresponding to the parent class . So the process is : Go back up to Object, Then the initialization block and construction method executed downward in turn , Until the previous subclass .
notes :
Static initialization block call order , The same as the order of constructor calls , Not in reuse .
边栏推荐
- Tsinghua University product: penalty gradient norm improves generalization of deep learning model
- Day05 錶格
- If you have just joined a new company, don't be fired because of your mistakes
- Webhook triggers Jenkins for sonar detection
- This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
- I stepped on a foundation pit today
- Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
- Contest3145 - the 37th game of 2021 freshman individual training match_ J: Eat radish
- The "two-way link" of pushing messages helps app quickly realize two-way communication capability
- 機器學習基礎:用 Lasso 做特征選擇
猜你喜欢
[latex] production of complex tables: excel2latex and detail adjustment
Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
Teach you how to optimize SQL
Li Chuang EDA learning notes 13: electrical network for drawing schematic diagram
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
What is cloud primordial?
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
Setting methods, usage methods and common usage scenarios of environment variables in postman
Redis transaction
Imperial cms7.5 imitation "D9 download station" software application download website source code
随机推荐
MySQL is dirty
Slurm view node configuration information
基於.NetCore開發博客項目 StarBlog - (14) 實現主題切換功能
JS object definition
ZABBIX API batch delete a template of the host
Handler source code analysis
Have you entered the workplace since the first 00???
Learning video website
Love and self-discipline and strive to live a core life
This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
[untitled]
Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon
Network communication basic kit -- IPv4 socket structure
Global and Chinese markets of advanced X-ray inspection system (Axi) in PCB 2022-2028: Research Report on technology, participants, trends, market size and share
Key knowledge of embedded driver
Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
Development of digital collection trading platform development of digital collection platform
Tsinghua University product: penalty gradient norm improves generalization of deep learning model