当前位置:网站首页>静态代码块永远先执行? 格局小了!!!
静态代码块永远先执行? 格局小了!!!
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这里就是照应了刚才说的红色的那一句话!!!
边栏推荐
- 为什么SELECT * 会导致查询效率低?
- 【无标题】
- Explain observer mode
- 買賣股票費用計算
- Implement global double finger long press to return to the desktop
- Integer partition
- 自动转换之-面试题
- Loggerfactory uses log4j Parameter introduction of properties
- How to suppress SiC MOSFET crosstalk?
- What are the advantages of a differential probe over a conventional probe
猜你喜欢

学习阿里如何进行数据指标体系的治理

rman备份报ORA-19809 ORA-19804

图解MySQL的binlog、redo log和undo log

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

【无标题】

Postman interface test

Characteristics and prevention of electrical fire
![[big case] Xuecheng online website](/img/40/beec3ba567f5a372899bb58af0d05a.png)
[big case] Xuecheng online website

High rise building fire prevention

Boundary value analysis method for learning basic content of software testing (2)
随机推荐
使用transform:scale之后导致页面鼠标悬浮事件消失
Quickly understand JVM structure and working principle
Assertions used in the interface automation platform
手机买同业存单基金开户选哪家证券公司比较好,比较安全呢
Common faults and solutions of Substation
Fire fighting work and measures in Higher Vocational Colleges
Operating principle of Rogowski coil
DEJA_VU3D - Cesium功能集 之 052-模拟卫星轨道(高空)效果
【云原生 | Kubernetes篇】深入了解Pod(六)
[share OpenGL tutorial]
Learn how Alibaba manages the data indicator system
自动转换之-面试题
redis5.0的槽点迁移,随意玩(单机迁移集群)
How do individuals open accounts to speculate in stocks? Is online account opening safe?
"Jianzhi offer" -- Interview Question 4: finding two-dimensional arrays
【大案例】学成在线网站
网上炒股开户安不安全?
Common test method used by testers --- orthogonal method
SQL注入之文件读写
Stock suspension