当前位置:网站首页>静态代码块永远先执行? 格局小了!!!
静态代码块永远先执行? 格局小了!!!
2022-06-28 09:06:00 【C_x_330】
public class Test
{
public static Test t1 = new Test();
{
System.out.println("blockA");
}
static
{
System.out.println("blockB");
}
public static void main(String[] args)
{
Test t2 = new Test();
}
}答案:blockAblockBblockA
我做这个题之前也有小疑问,为什么最开始不是先加载静态代码里面内容,导致我做错!
看完题解后,发现
publicstaticTest t1 =newTest();这个创建的对象t1也是静态的,所以这里得出结论:当都是静态的情况下,按照顺序先后执行!所以创建完静态的t1之后,依次往下执行创建t1时触发的构造代码块,然后按循序在执行静态代码块,然后在执行创建t2时候的构造代码块!
但是如果我把静态代码块放到
publicstaticTest t1 =newTest();执行这个语句之前那结果又会是怎么样?
答案:blockBblockAblockA这里就是照应了刚才说的红色的那一句话!!!
边栏推荐
- Implementation of single sign on
- new URL(“www.jjj.com“)
- MATLAB小技巧(20)矩阵分析--主成分回归
- 图解MySQL的binlog、redo log和undo log
- STL - inverter
- JMeter -- interface test 1
- Apiccloud, together with 360 Tianyu, helps enterprises keep the "first pass" of APP security
- 批量修改表和表中字段排序规则
- 实现全局双指长按返回桌面
- What are the advantages of a differential probe over a conventional probe
猜你喜欢

rman备份报ORA-19809 ORA-19804

RMAN backup message ora-19809 ora-19804

Apache Doris becomes the top project of Apache

Construire le premier réseau neuronal avec pytorch et optimiser

Calcul des frais d'achat et de vente d'actions

Why does select * lead to low query efficiency?

Basic knowledge of hard disk (head, track, sector, cylinder)

买卖股票费用计算

MySQL8.0 忘记 root 密码

Expérience d'optimisation SQL: de 30248 secondes à 0001 secondes
随机推荐
JMeter -- interface test 2
Implementation of single sign on
Common faults and solutions of Substation
我想网上注册股票开户,如何操作?在线开户安全么?
Android studio interview preparation
玩玩sftp上传文件
[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service
Deployment of MySQL database in Linux Environment
为什么SELECT * 会导致查询效率低?
Comment supprimer le crosstalk SiC MOSFET?
电子元器件销售ERP管理系统哪个比较好?
The Cassandra cluster reinstalls and starts from the node. An error is reported. There is an existing solution
MATLAB小技巧(20)矩阵分析--主成分回归
Potential safety hazards in elderly care facilities
从知识到智慧:知识图谱还要走多远?
104. maximum depth of binary tree
Play SFTP upload file
Stock suspension
containerd1.5.5的安装
spark的资源调度和任务调度