当前位置:网站首页>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 ,
边栏推荐
- DEJA_ Vu3d - 052 of cesium feature set - Simulation of satellite orbit (high altitude) effect
- SQL injection file read / write
- Music website design based on harmonyos (portal page)
- Illustration of MySQL binlog, redo log and undo log
- redis5.0的槽点迁移,随意玩(单机迁移集群)
- 如何实现基于 RADIUS 协议的双因子认证 MFA?
- How do I open an account on my mobile phone? Is it safe to open an account online now?
- How to suppress SiC MOSFET crosstalk?
- 1182: group photo effect
- Apache Doris becomes the top project of Apache
猜你喜欢

为什么SELECT * 会导致查询效率低?

STL -- binder

Matlab tips (20) matrix analysis -- principal component regression

1182: group photo effect

The Cassandra cluster reinstalls and starts from the node. An error is reported. There is an existing solution

SQL 優化經曆:從 30248秒到 0.001秒的經曆

How to solve the problem of high concurrency and seckill

From knowledge to wisdom: how far will the knowledge map go?

Expérience d'optimisation SQL: de 30248 secondes à 0001 secondes

STL - inverter
随机推荐
硬盘基本知识(磁头、磁道、扇区、柱面)
Calcul des frais d'achat et de vente d'actions
两道面试小Demo
Which is a better ERP management system for electronic component sales?
从知识到智慧:知识图谱还要走多远?
The Cassandra cluster reinstalls and starts from the node. An error is reported. There is an existing solution
网上炒股开户安不安全?
我想网上注册股票开户,如何操作?在线开户安全么?
用Pytorch搭建第一個神經網絡且進行優化
How to implement two factor authentication MFA based on RADIUS protocol?
股票 停牌
Ffmpeg streaming fails to update header with correct duration
買賣股票費用計算
Batch modify tables and sorting rules for fields in tables
Apiccloud, together with 360 Tianyu, helps enterprises keep the "first pass" of APP security
Expérience d'optimisation SQL: de 30248 secondes à 0001 secondes
containerd1.5.5的安装
自动转换之-面试题
Illustration of MySQL binlog, redo log and undo log
A - Bi-shoe and Phi-shoe