当前位置:网站首页>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 .
边栏推荐
- 304. Merge two ordered arrays
- Sonarqube local installation
- Study notes on the introduction paper of face recognition deep facial expression recognition: a survey
- MySQL performance analysis - explain
- Summary of various installation methods of Lab View
- 軟件測試的幾種分類,一看就明了
- Wikipedia User Guide
- Introduction to convolutional neural network
- 4K sea bottom and water surface fabrication method and ocean bump displacement texture Download
- HashSet underlying source code
猜你喜欢

Leetcode question brushing 04 string

Set and array conversion, list, array

Install pycharm process

leetcode 142. Circular linked list II

Introduction to common activation functions
![[projet cs144 de Stanford Computing Network] lab1: Stream reassembler](/img/7b/fad18b68a6ee30d1dec4dad6273b98.png)
[projet cs144 de Stanford Computing Network] lab1: Stream reassembler

Happy string

Five classic articles worth reading

How to print infinite symbol in WPS

Uuid/guid introduction, generation rules and generation codes
随机推荐
Realization of flip animation
Large end storage and small end storage
Transaction characteristics and isolation levels
Spit bubbles (stack)
Docker install MySQL
Page optimization - Notes
Leetcode-19- delete the penultimate node of the linked list (medium)
Set and array conversion, list, array
ES6解构赋值
Create a simple game interface using pyGame
QT color extraction
V-inline-date, similar to Ctrip, flying pig, time selection with price
Continue when the condition is not asked, execute the parameter you compare
Introduction to convolutional neural network
leetcode. 349. intersection of two arrays
Phaser3 load
4K sea bottom and water surface fabrication method and ocean bump displacement texture Download
Leetcode question brushing 02 linked list operation
ES6 deconstruction assignment
Golang context (context summary)