从零单排_JAVA 青铜4(构造器,初始化块)
来源:互联网 发布:软件著作权模板 编辑:程序博客网 时间:2024/05/16 09:26
- 构造器
在需要有参数有参数构造器时,要自己把无参构造器写出来。 - 初始化块
初始化块在编译后会回到所有的构造器中。 初始化块、构造器 等的执行顺序:
package com.henry.day2.baseClass;class Root{ static{ System.out.println("root 的静态初始化快"); } { System.out.println("root 的普通初始化块"); } public Root(){ System.out.println("root 的无参数构造器"); } public Root(String str){ System.out.println("root 的有参数构造器" ); } } class Mid extends Root{ static{ System.out.println("mid 的静态初始化块"); } { System.out.println("mid 的普通初始化块"); } public Mid(){ System.out.println("mid 的无参数构造器"); } public Mid(String str){ this(); System.out.println("mid 的有参数构造器"); } } public class Leaf extends Mid { static{ System.out.println("leaf 的静态初始化块"); } { System.out.println("leaf 的初始化块"); } public Leaf(){ System.out.println("leaf 的无参数构造器"); } public Leaf(String str){ super(str); System.out.println("leaf 的有参数构造器"); } public static void main(String[] args) { new Leaf("test"); System.out.println("==========="); new Leaf(); } }
root 的静态初始化快
mid 的静态初始化块
leaf 的静态初始化块
root 的普通初始化块
root 的无参数构造器
mid 的普通初始化块
mid 的无参数构造器
mid 的有参数构造器
leaf 的初始化块
leaf 的有参数构造器
root 的普通初始化块
root 的无参数构造器
mid 的普通初始化块
mid 的无参数构造器
leaf 的初始化块
leaf 的无参数构造器
阅读全文
0 0
- 从零单排_JAVA 青铜4(构造器,初始化块)
- 从零单排_JAVA 青铜5(背景知识,UML图,基本数据类型)
- 从零单排_JAVA 开局
- 从零单排4
- 从零单排c++ primer(4)
- C++ 从零单排(4)- ACM二
- 从零单排c++ primer(1)
- 从零单排c++ primer(2)
- 从零单排c++ primer(3)
- 从零单排c++ primer(5)
- 从零单排c++ primer(6)
- 从零单排c++ primer(7)
- 从零单排c++ primer(8)
- 从零单排c++ primer(9)
- 从零单排c++ primer(10)
- 从零单排c++ primer(11)
- 从零单排c++ primer(12)
- 从零单排c++ primer(13)
- 引用Aspose.Words,操作Word模板创建表格
- CTF实验吧-因缺思汀的绕过【group by,with rollup,limit offset的利用】
- PicPick的安装方法
- promise then catch
- 异步fifo的设计(一)
- 从零单排_JAVA 青铜4(构造器,初始化块)
- java学习笔记
- ubuntu_git下远程提交代码
- Jenkins安装配置
- 串口M1卡读写模块,串口Mifare 读写模块,串口Ntag213/215/216读写模块
- 把符合日期格式的字符串解析成日期
- 单点登录原理与简单实现
- AndroidStudio 相同jar包配置文件冲突(DuplicateFileException)
- 用R语言DIY机器学习算法--Kmeans