当前位置:网站首页>静态代码块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的构造方法
边栏推荐
猜你喜欢
随机推荐
Redis主从复制以及哨兵模式
Redis五种基本类型
[daily practice] realization of product card animation effect
VIM from dislike to dependence (19) -- substitution
[c++ primer notes] Chapter 4 expression
"Short video" Linxia fire rescue detachment carries out fire safety training
Chapter 11 signal (I) - concept
No matter how good LCD and OLED display technologies are, they cannot replace this ancient display nixie tube
分析日志.log
[batch dos-cmd command - summary and summary] - map folder to virtual disk - subst
How Oracle converts strings to multiple lines
vim 从嫌弃到依赖(19)——替换
ServletConfig与ServletContext
C# 解决使用SQLite 的相对路径问题
Linux下Redis的安装
Order by injection of SQL injection
That is, a one-stop live broadcast service with "smooth live broadcast" and full link upgrade
Helix QAC更新至2022.1版本,将持续提供高标准合规覆盖率
並發編程JUC的AQS底層源碼
2022 love analysis · panoramic report of it operation and maintenance manufacturers