当前位置:网站首页>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 .
边栏推荐
- Formulaire day05
- 長文綜述:大腦中的熵、自由能、對稱性和動力學
- Rhcsa day 2
- Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
- Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
- ZABBIX API batch delete a template of the host
- Slurm view node configuration information
- 2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
- Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
- Teach you how to optimize SQL
猜你喜欢
Consul of distributed service registration discovery and unified configuration management
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Lichuang EDA learning notes 14: PCB board canvas settings
ZABBIX API pulls the values of all hosts of a monitoring item and saves them in Excel
Add IDM to Google browser
Jenkins configures IP address access
Development of digital collection trading platform development of digital collection platform
Have you entered the workplace since the first 00???
If you have just joined a new company, don't be fired because of your mistakes
Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
随机推荐
what does ctrl + d do?
Global and Chinese markets for electroencephalogram (EEG) devices 2022-2028: Research Report on technology, participants, trends, market size and share
2022 attached lifting scaffold worker (special type of construction work) free test questions and attached lifting scaffold worker (special type of construction work) examination papers 2022 attached
Contest3145 - the 37th game of 2021 freshman individual training match_ J: Eat radish
Bugku Zhi, you have to stop him
Is online futures account opening safe and reliable? Which domestic futures company is better?
Keepalived set the master not to recapture the VIP after fault recovery (it is invalid to solve nopreempt)
Global and Chinese market for travel wheelchairs 2022-2028: Research Report on technology, participants, trends, market size and share
Amélioration de l'efficacité de la requête 10 fois! 3 solutions d'optimisation pour résoudre le problème de pagination profonde MySQL
Key knowledge of embedded driver
Add IDM to Google browser
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]
Database concept and installation
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
Imperial cms7.5 imitation "D9 download station" software application download website source code
Buuctf QR code
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Global and Chinese market of small batteries 2022-2028: Research Report on technology, participants, trends, market size and share
VRRP+BFD
Webhook triggers Jenkins for sonar detection