当前位置:网站首页>The constructor is never executed immediately after new()!!!!!
The constructor is never executed immediately after new()!!!!!
2022-06-28 09:08:00 【C_ x_ three hundred and thirty】
In the delegate event model , The source generates an event and sends it to one or more listeners , Each listener must register with the event source .
The result of the following procedure is :
class X{
Y y=new Y();
public X(){
System.out.print("X");
}
}
class Y{
public Y(){
System.out.print("Y");
}
}
public class Z extends X{
Y y=new Y();
public Z(){
System.out.print("Z");
}
public static void main(String[] args) {
new Z();
}
}
YXYZ
This is a very valuable question for me !
I used to think new Z(); after , Just do it Z The construction method of is back , But the fact is that my pattern is smaller .
When you new Z() after , I will first see if there is any inheritance relationship ,
If so, you will jump to the parent class first ,
The first thing to do in the parent class is not to execute the constructor of the parent class
The first thing is to initialize the member variables defined in the parent class ( Go through it one by one ), The constructor of the parent class will not be executed until the member variable is initialized ,
边栏推荐
- Where is CentOS mysql5.5 configuration file
- 股票 停牌
- Assertions used in the interface automation platform
- MATLAB小技巧(20)矩阵分析--主成分回归
- 中金财富开户安全吗?怎么收费?
- From knowledge to wisdom: how far will the knowledge map go?
- Comment supprimer le crosstalk SiC MOSFET?
- Almost union find (weighted union search)
- Which securities company is better and safer to choose when opening an account for the inter-bank certificate of deposit fund with mobile phone
- 1182: effets de la photo de groupe
猜你喜欢
JMeter -- interface test 1
The Cassandra cluster reinstalls and starts from the node. An error is reported. There is an existing solution
Music website design based on harmonyos (portal page)
Application of energy management system in iron and steel enterprises
Characteristics and prevention of electrical fire
new URL(“www.jjj.com“)
Apache Doris 成为 Apache 顶级项目
Basic knowledge of hard disk (head, track, sector, cylinder)
硬盘基本知识(磁头、磁道、扇区、柱面)
Screen settings in the source code of OBS Live Room
随机推荐
Apiccloud, together with 360 Tianyu, helps enterprises keep the "first pass" of APP security
SQL 优化经历:从 30248秒到 0.001秒的经历
Application of energy management system in iron and steel enterprises
Find the total number of 1 appearing in the integer 1-N and the number of 1 in the binary of the integer
Test cases for learning the basic content of software testing (II)
Where is CentOS mysql5.5 configuration file
Discussion on safety management of centralized maintenance construction site of substation under the mode of operation and maintenance
Illustration of MySQL binlog, redo log and undo log
DEJA_VU3D - Cesium功能集 之 052-模拟卫星轨道(高空)效果
网上炒股开户安不安全?
[share OpenGL tutorial]
From knowledge to wisdom: how far will the knowledge map go?
Resource scheduling and task scheduling of spark
買賣股票費用計算
Which is a better ERP management system for electronic component sales?
理解IO模型
如何实现基于 RADIUS 协议的双因子认证 MFA?
图解MySQL的binlog、redo log和undo log
Construire le premier réseau neuronal avec pytorch et optimiser
1182: group photo effect