当前位置:网站首页>Do static code blocks always execute first? The pattern is smaller!!!
Do static code blocks always execute first? The pattern is smaller!!!
2022-06-28 09:12:00 【C_ x_ three hundred and thirty】
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();
}
}answer :blockAblockBblockA
I have a little question before I do this problem , Why don't you load the contents of static code first , Cause me to do wrong !
After reading the solution , Find out
publicstaticTest t1 =newTest();This created object t1 It's also static , So here comes the conclusion : When all are static , Execute in sequence ! So after creating the static t1 after , Execute the creation step by step t1 Constructor code block triggered when , Then execute the static code block in sequence , Then, after executing the create t2 Construction code block of time !
But if I put static code blocks in
publicstaticTest t1 =newTest(); What will happen before this statement is executed ?
answer :blockBblockAblockAHere is the reference to the red sentence just said !!!
边栏推荐
- 自动转换之-面试题
- Screen settings in the source code of OBS Live Room
- 电子元器件销售ERP管理系统哪个比较好?
- Ffmpeg streaming fails to update header with correct duration
- Operating principle of Rogowski coil
- Rich text - Test Case
- It only takes two steps to find the right PMP organization, one check and two questions
- break database---mysql
- Fastjason filter field
- What are the advantages of a differential probe over a conventional probe
猜你喜欢

使用transform:scale之后导致页面鼠标悬浮事件消失

Common test method used by testers --- orthogonal method

SQL 优化经历:从 30248秒到 0.001秒的经历

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

图解MySQL的binlog、redo log和undo log

Data modeling based on wide table

SQL 優化經曆:從 30248秒到 0.001秒的經曆

用Pytorch搭建第一个神经网络且进行优化

Test cases for learning the basic content of software testing (II)

学习阿里如何进行数据指标体系的治理
随机推荐
Characteristics and prevention of electrical fire
Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
为什么SELECT * 会导致查询效率低?
手机买同业存单基金开户选哪家证券公司比较好,比较安全呢
Common tools for interface testing --postman
小程序 :遍历list里面的某个数组的值,等同于 for=“list” list.comment里面的某一项
spark的资源调度和任务调度
SQL injection file read / write
Avframe Memory Management API
Which is a better ERP management system for electronic component sales?
Chrome devtools
1181:整数奇偶排序
Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
Guangzhou: new financial activities and new opportunities for enterprises
Redis5.0 slot migration, free play (single machine migration cluster)
Key points of building fire protection design
Deployment of MySQL database in Linux Environment
硬盘基本知识(磁头、磁道、扇区、柱面)
containerd1.5.5的安装
Assertions used in the interface automation platform