标签:
5.1 构造器初始化
5.2 方法重载
5.3 垃圾回收
5.4 成员变量初始化
package com.chenlei.study.thinkinginjava; class Base{ Base(String msg){ System.out.println(msg); } } class Father{ static Base staticBaseFather = new Base("staticBaseFather specify"); static Base staticBaseFather1; static{ staticBaseFather1 = new Base("staticBaseFather static area"); } Base base = new Base("fieldBaseFather specify"); Base base1; { base1 = new Base("fieldBaseFather non-static area"); } Base base2; public Father() { base2 = new Base("fieldBaseFather constructor"); } } class Child extends Father{ static Base staticBaseChild = new Base("staticBaseChild specify"); static Base staticBaseChild1; static{ staticBaseChild1 = new Base("staticBaseChild static area"); } Base base1; { base1 = new Base("fieldBaseChild non-static area"); } Base base = new Base("fieldBaseChild specify"); Base base2; public Child() { base2 = new Base("fieldBaseChild constructor"); } } public class Initalized { public static void main(String[] args) { new Child(); } }
output:
staticBaseFather specify staticBaseFather static area staticBaseChild specify staticBaseChild static area fieldBaseFather specify fieldBaseFather non-static area fieldBaseFather constructor fieldBaseChild non-static area fieldBaseChild specify fieldBaseChild constructor
标签:
原文地址:http://www.cnblogs.com/Vabshroo/p/5492639.html