当前位置:网站首页>构造方法绝不是在new()之后就立马执行!!!!!
构造方法绝不是在new()之后就立马执行!!!!!
2022-06-28 09:06:00 【C_x_330】
在委托事件模型中,源生成事件并把它发送给一个或多个监听器,每个监听器必须向事件源注册。
以下程序执行的结果是:
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
这个题对我来说算是一道很有价值的题!
我以前误以为new Z();后,就仅仅的去执行Z的构造方法就退回来了,但实际是我格局小了。
当你new Z()后,会先看看有没有继承关系,
有的话会先跳转到父类里面,
到父类里面第一件事不是执行父类的构造方法
而第一件事是先去把父类中定义的成员变量初始化一边(依次顺着过一遍),等初始化成员变量之后才会去执行父类的构造方法,
边栏推荐
- How to implement two factor authentication MFA based on RADIUS protocol?
- Comment supprimer le crosstalk SiC MOSFET?
- Implementation of code scanning login
- Expérience d'optimisation SQL: de 30248 secondes à 0001 secondes
- A - Bi-shoe and Phi-shoe
- Assertions used in the interface automation platform
- Apiccloud, together with 360 Tianyu, helps enterprises keep the "first pass" of APP security
- Power data
- Android studio interview preparation
- rman備份報ORA-19809 ORA-19804
猜你喜欢

Apache Doris becomes the top project of Apache

Discussion on the improvement and application of the prepayment system in the management of electricity charge and price

SQL optimization experience: from 30248 seconds to 0.001 seconds

图解MySQL的binlog、redo log和undo log

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

基于宽表的数据建模

Guangzhou: new financial activities and new opportunities for enterprises

【无标题】

DEJA_VU3D - Cesium功能集 之 051-地形开挖完美实现

spark的资源调度和任务调度
随机推荐
Robot Rapping Results Report
How to solve the problem of high concurrency and seckill
个人究竟如何开户炒股?在线开户安全么?
Is it safe to open an account for mobile phone stock speculation?
Basic content learning of software testing (I)
Application of energy management system in iron and steel enterprises
学习阿里如何进行数据指标体系的治理
Protection range and optimization of motor protector for hoist equipment
centos mysql5.5配置文件在哪
状态机程序框架
Characteristics and prevention of electrical fire
【无标题】
Redis5.0 slot migration, free play (single machine migration cluster)
Superimposed ladder diagram and line diagram and merged line diagram and needle diagram
Guangzhou: new financial activities and new opportunities for enterprises
STL -- binder
Discussion on safety management of centralized maintenance construction site of substation under the mode of operation and maintenance
【无标题】
Quickly understand JVM structure and working principle
Is it safe for Huatai Securities to open an account online? What is the handling process