当前位置:网站首页>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 ,
边栏推荐
- [share OpenGL tutorial]
- 股票 停牌
- Stock suspension
- Data mining modeling practice
- Webrtc advantages and module splitting
- The Cassandra cluster reinstalls and starts from the node. An error is reported. There is an existing solution
- How to solve the problem of port number occupation
- How to solve the problem of high concurrency and seckill
- Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
- Quickly understand JVM structure and working principle
猜你喜欢

"Jianzhi offer" -- Interview Question 4: finding two-dimensional arrays

用Pytorch搭建第一個神經網絡且進行優化
![[untitled]](/img/bb/213f213c695795daecb81a4cf2adcd.jpg)
[untitled]

股票 停牌

Almost union find (weighted union search)

Valentine's Day - VBS learning (sentences, love words)

High rise building fire prevention

Import and export of a single collection in postman

How to suppress SiC MOSFET crosstalk?

Calculation of stock purchase and sale expenses
随机推荐
Music website design based on harmonyos (portal page)
Implement global double finger long press to return to the desktop
Analysis of prepaid power purchase device
Decision table method for basic content learning of software testing (2)
Almost union find (weighted union search)
[untitled]
Is it safe for CICC fortune to open an account? How much do you charge?
Characteristics and prevention of electrical fire
Campus honey decoration of APP course design (e-commerce platform)
小程序 :遍历list里面的某个数组的值,等同于 for=“list” list.comment里面的某一项
为什么SELECT * 会导致查询效率低?
买卖股票费用计算
How do individuals open accounts to speculate in stocks? Is online account opening safe?
Goldbach`s Conjecture
Privacy computing fat----- offline prediction
Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
Use of Jasper soft studio report tool and solution of thorny problems
Is it safe to open an account for online stock speculation?
自动转换之-面试题