当前位置:网站首页>静态代码块Vs构造代码块
静态代码块Vs构造代码块
2022-06-27 08:25:00 【C_x_330】
class A {
public A() {
System.out.println("class A");
}
{ System.out.println("I'm A class"); }
static { System.out.println("class A static"); }
}
public class B extends A {
public B() {
System.out.println("class B");
}
{ System.out.println("I'm B class"); }
static { System.out.println("class B static"); }
public static void main(String[] args) {
new B(); class A static class B static I'm A class class A I'm B class class B
当new 一个对象时
如果有静态代码块
系统会自动的帮你最先执行静态代码块
如果A继承了B 并且A,B都有静态代码块
当你new A()时,
系统会自动的先去执行B的静态代码块在执行A的静态代码块
然后假设B还有构造代码块,那么再执行完A,B的静态代码块后
会再去执行B的构造代码块,然后在执行B的构造方法
然后在执行A的构造代码块,然后在执行A的构造方法
边栏推荐
- Etcd tutorial - Chapter 5 etcd etcdctl usage
- 并发编程JUC的AQS底层源码
- Linux下Redis的安装
- 【云原生】2.3 Kubernetes 核心实战(上)
- Reference | upgrade win11 mobile hotspot can not be opened or connected
- Persistence mechanism of redis
- 准备好迁移上云了?请收下这份迁移步骤清单
- Ue5 magic power - POI solution
- Correctly understand MySQL mvcc
- That is, a one-stop live broadcast service with "smooth live broadcast" and full link upgrade
猜你喜欢

爬一个网页的所有导师信息

Five basic types of redis

After working in a large factory for ten years with an annual salary of 400000 yuan, I was suddenly laid off. If the company wanted to abandon you, it wouldn't leave any kindness

参考 | Win11 开启热点之后电脑不能上网

Blind survey shows that female code farmers are better than male code farmers

JVM层次上的对象的创建过程和内存布局

PayPal account has been massively frozen! How can cross-border sellers help themselves?

Oracle uses an SQL to find out which data is not in a table

vim 从嫌弃到依赖(19)——替换

Associated GIS: all roads lead to ue5 City
随机推荐
Redis master-slave replication and sentinel mode
How Oracle converts strings to multiple lines
Read datasets iteratively with xgboost
sql注入之order by注入
力扣84柱状图中最大的矩形
Rust async: SMOL source code analysis -executor
SPARQL basic introductory exercise
DataV轮播表组件dv-scroll-board宽度问题
Is futures reverse documentary reliable?
Modify the contents of /etc/crontab file directly, and the scheduled task will not take effect
ArrayList和LinkedList的区别
JS EventListener
2022.6.26-----leetcode. seven hundred and ten
oracle怎样将字符串转为多行
直接修改/etc/crontab 文件内容,定时任务不生效
Time function calculation efficiency of C
Redis配置文件详解
MySQL lock details
MySQL索引详解
2022.06.26 (LC Luo 6101 Luo determines whether the matrix is an X matrix)