当前位置:网站首页>构造方法绝不是在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()后,会先看看有没有继承关系,
有的话会先跳转到父类里面,
到父类里面第一件事不是执行父类的构造方法
而第一件事是先去把父类中定义的成员变量初始化一边(依次顺着过一遍),等初始化成员变量之后才会去执行父类的构造方法,
边栏推荐
- 【无标题】
- Rich text - Test Case
- Valentine's Day - VBS learning (sentences, love words)
- It only takes two steps to find the right PMP organization, one check and two questions
- A - deep sea exploration
- Power data
- 怎样在手机上开户?现在网上开户安全么?
- Almost union find (weighted union search)
- 图解MySQL的binlog、redo log和undo log
- Data mining modeling practice
猜你喜欢

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

【云原生 | Kubernetes篇】深入了解Pod(六)

Import and export of a single collection in postman

罗氏线圈可以测量的大电流和频率范围

Operating principle of Rogowski coil

Using transform:scale causes the page mouse hover event to disappear

图解MySQL的binlog、redo log和undo log

电子元器件销售ERP管理系统哪个比较好?

Learn how Alibaba manages the data indicator system

Comment supprimer le crosstalk SiC MOSFET?
随机推荐
From knowledge to wisdom: how far will the knowledge map go?
状态机程序框架
华泰证券网上开户安全吗 办理流程是什么
学习阿里如何进行数据指标体系的治理
Which is a better ERP management system for electronic component sales?
Android studio interview preparation
Loggerfactory uses log4j Parameter introduction of properties
我想网上注册股票开户,如何操作?在线开户安全么?
【无标题】
Campus honey decoration of APP course design (e-commerce platform)
Integer partition
硬盘基本知识(磁头、磁道、扇区、柱面)
Test cases for learning the basic content of software testing (II)
图解MySQL的binlog、redo log和undo log
Import and export of a single collection in postman
Analysis of prepaid power purchase device
Common test method used by testers --- orthogonal method
High rise building fire prevention
Super Jumping! Jumping! Jumping!
How to implement two factor authentication MFA based on RADIUS protocol?