当前位置:网站首页>Subclass a inherits from parent class B, a a = new a(); Then the execution sequence of the constructor of parent class B, the static code block of parent class B, the non static code block of parent c
Subclass a inherits from parent class B, a a = new a(); Then the execution sequence of the constructor of parent class B, the static code block of parent class B, the non static code block of parent c
2022-06-25 11:20:00 【User 9854323】
(1) Subclass A Inherited parent class B, A a = new A(); be :
Parent class B Static code block -> Subclass A Static code block -> Parent class B Non static code block -> Parent class B Constructors -> Subclass A Non static code block -> Subclass A Constructors
(2) If a subclass constructor explicitly calls a constructor of the parent class , Then call the constructor
class C {
C() {
System.out.print("C");
}
}
class A {
C c = new C();
A() {
this("A");
System.out.print("A");
}
A(String s) {
System.out.print(s);
}
}
class Test extends A {
Test() {
super("B");
System.out.print("B");
}
public static void main(String[] args) {
new Test();
}
}CBB First new A subclass object , Then you need to call the constructor to initialize the subclass object , But this class inherits from A, So you need to call the constructor of the parent class first , Through here super(“B”) The shown calls the parameterized construct of the parent class . Initialize the objects in the parent class before executing the parameterized construction of the parent class , To the c Members are initialized , Called C Nonparametric construction of class , So the call order is : First call C Nonparametric construction of class Call again A Class with parameters Finally, call the construction of subclasses
(3) stay JVM call mian Method is used to initialize the static content . In sequence : Static variable of parent class , The static code block of the parent class , Static variables of subclasses , Static code block of subclass .
public class Test{
static int cnt = 6;
static{
cnt += 9;
}
public static void main(string[] args){
System.out.println(“cnt =” + cnt);
}
static{
Cnt /=3;
};
}Cnt=5
边栏推荐
- A difficult mathematical problem baffles two mathematicians
- wait()、notify()和notifyAll()、sleep()、Condition、await()、signal()
- Vulnérabilité à l'injection SQL (contournement)
- Use of three-level linkage plug-ins selected by provinces and cities
- How to realize the rich text editor function of mobile terminal
- 从GEE中免费获取全球人类住区层 (GHSL) 数据集
- MySQL and Oracle processing CLOB and blob fields
- 金仓数据库 KingbaseES 插件ftutilx
- Android之Kotlin语法详解与使用
- 视频会议一体机的技术实践和发展趋势
猜你喜欢

SystemVerilog(十三)-枚举数据类型

【文件包含漏洞-04】经典面试题:已知某网站仅存在本地文件包含漏洞时,如何GetShell?

基于SSH的高校实验室物品管理信息系统的设计与实现 论文文档+项目源码及数据库文件

Dragon Book tiger Book whale Book gnawing? Try the monkey book with Douban score of 9.5

今天16:00 | 中科院计算所研究员孙晓明老师带大家走进量子的世界

中国信通院沈滢:字体开源协议——OFL V1.1介绍及合规要点分析

查询法,中断法实现USART通信

Apache ShenYu 入门

Getting started with Apache Shenyu

网易开源的分布式存储系统 Curve 正式成为 CNCF 沙箱项目
随机推荐
Shen Ying, China Academy of communications and communications: font open source protocol -- Introduction to ofl v1.1 and analysis of key points of compliance
Daily 3 questions (3) - check whether integers and their multiples exist
反应c语言程序结构特点的程序
An interesting logic SRC mining
Introduction to socket UDP and TCP
基于OpenStreetMap+PostGIS的地理位置系统 论文文档+参考论文文献+项目源码及数据库文件
杭州/北京内推 | 阿里达摩院招聘视觉生成方向学术实习生(人才计划)
牛客网:旋转数组
【文件包含漏洞-03】文件包含漏洞的六种利用方式
Big Endian 和 Little Endian
Jincang database kingbasees plug-in force_ view
At 16:00 today, Mr. sunxiaoming, a researcher of the Institute of computing, Chinese Academy of Sciences, took you into the quantum world
GaussDB others内存比较高的场景
SQL注入漏洞(繞過篇)
2022 PMP project management examination agile knowledge points (2)
SQL注入漏洞(类型篇)
基于SSH的高校实验室物品管理信息系统的设计与实现 论文文档+项目源码及数据库文件
MySQL synchronous data configuration and shell script implementation
[file inclusion vulnerability-04] classic interview question: how to getshell when a website is known to have only local file inclusion vulnerability?
GaussDB 集群维护案例集-sql执行慢