当前位置:网站首页>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 .
边栏推荐
- #pragma comment(lib,“urlmon.lib“)
- Stack and queue practice (C language): Demon King's language
- The storage structure of a tree can adopt the parent representation, that is, the parent pointer array representation. Try to give the corresponding class definition. Each tree node contains two membe
- 使用Pygame创建一个简单游戏界面
- Leetcode-12- integer to Roman numeral (medium)
- Wikipedia API User Guide
- Study notes on the introduction paper of face recognition deep facial expression recognition: a survey
- Web Application & applet application deployment
- Set and array conversion, list, array
- 【斯坦福计网CS144项目】Lab1: StreamReassembler
猜你喜欢

Minimum score of one question per day
![[Stanford Jiwang cs144 project] lab1: streamreassembler](/img/7b/fad18b68a6ee30d1dec4dad6273b98.png)
[Stanford Jiwang cs144 project] lab1: streamreassembler

MySQL connection query

Go JWT learning summary

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

Temporary objects and compilation optimization

在国企做软件测试工程师是一种什么样的体验:每天过的像打仗一样

redis

Mathematical knowledge arrangement: extremum & maximum, stagnation point, Lagrange multiplier

Realization of flip animation
随机推荐
How to turn on the hotspot for the mobile phone after the computer is connected to the network cable
Leetcode-18- sum of four numbers (medium)
[Andoid][踩坑]CTS 11_r3开始出现的testBootClassPathAndSystemServerClasspath_nonDuplicateClasses FAIL问题分析
Wikipedia User Guide
Go JWT learning summary
Stack stack LIFO
Alexnet implements image classification of caltech101 dataset (pytorch Implementation)
Vector|hdu-4841 round table questions
Rasa dialogue robot helpdesk (III)
Wikipedia API User Guide
Method of cleaning C disk
4K sea bottom and water surface fabrication method and ocean bump displacement texture Download
Leetcode question brushing 04 string
ng-tv-focusable
leetcode. 151. flip the words in the string
D template instance does not match declaration
V-inline-date, similar to Ctrip, flying pig, time selection with price
redis
Leetcode-19- delete the penultimate node of the linked list (medium)
ArrayList underlying source code