当前位置:网站首页>About constructive code blocks, static code blocks, and constructor execution order
About constructive code blocks, static code blocks, and constructor execution order
2022-06-13 01:28:00 【superJuice】
- Common code block : Method body of common method
- Building blocks of code : use
{}The code of the package - Static code block : use
static{}The code of the package
public class MethodTest {
private String tag;
static {
System.out.println(" Static code block ");
}
{
System.out.println(" Building blocks of code ");
}
public MethodTest(String tag) {
this.tag = tag;
System.out.println(tag + " Constructors ");
}
public void test() {
System.out.println(tag + " Common code block ");
}
public static void main(String[] args) {
MethodTest test1 = new MethodTest("test1");
test1.test();
MethodTest test2 = new MethodTest("test2");
test2.test();
}
}
Running results : Static code block Building blocks of code test1 Constructors test1 Common code block Building blocks of code test2 Constructors test2 Common code block
It can be seen from the running results that :
- The construction code block calls each time an object is created , Execute before constructor .
- Static code blocks are executed only once when the object is first created , And execute... Before constructing code blocks .
边栏推荐
- 【斯坦福计网CS144项目】Lab1: StreamReassembler
- Method of cleaning C disk
- Argparse command line passes list type parameter
- Network communication tcp/ip
- Stack and queue practice (C language): Demon King's language
- Sliding window summary of TCP connections
- leetcode 142. Circular linked list II
- np. Understanding of axis in concatenate
- How to solve the problem of database?
- [WSL2]WSL2迁移虚拟磁盘文件ext4.vhdx
猜你喜欢
![[latex] insérer une image](/img/0b/3304aaa03d3fea3ebb93b0348c3131.png)
[latex] insérer une image
![[latex] insert picture](/img/0b/3304aaa03d3fea3ebb93b0348c3131.png)
[latex] insert picture

C language implementation of the classic eight queens problem

Argparse command line passes list type parameter

软件测试的几种分类,一看就明了

FLIP动画实现思路

Traversal of binary tree - first order traversal, middle order traversal, and second order traversal

项目实训(十七)---个人工作总结

DFS and BFS notes (II): depth first search (implemented in C language)

redis
随机推荐
leetcode. 151. flip the words in the string
Go JWT learning summary
Stack stack LIFO
The tle4253gs is a monolithic integrated low dropout tracking regulator in a small pg-dso-8 package.
Large end storage and small end storage
【斯坦福計網CS144項目】Lab1: StreamReassembler
Five classic articles worth reading
Application advantages of 5g industrial gateway in coal industry
Happy string
np.concatenate中axis的理解
Camera model_
Spit bubbles (stack)
QT color extraction
[WSL2]限制WSL2可访问的硬件资源(CPU/内存)
Summary of various installation methods of Lab View
Leetcode-18- sum of four numbers (medium)
Plusieurs catégories de tests logiciels sont claires à première vue
Leetcode-11- container with the most water (medium)
[Latex] 插入圖片
Leetcode question brushing 06 bit operation