package xu.jin; class Insect{ private int i=print("hello i"); Insect(){System.out.println("Insect"+i);} { System.out.println("1"); System.out.println("2"); } static{ System.out.println("3"); System.out.println("4"); } static int print(String str){ System.out.println(str); return 2; } static int x1=print("static Insect"); } class hello extends Insect{ private int j=print(" hello j"); static int x2=print("static hello"); hello(){ System.out.println("hello"+j); } { System.out.println("11"); System.out.println("22"); } static{ System.out.println("33"); System.out.println("44"); } public static void main(String[] args) { // TODO Auto-generated method stub hello sCat=new hello(); //Insect ins=new Insect(); System.out.println("hello world"); } }
output:
3 4 static Insect static hello 33 44 hello i 1 2 Insect2 hello j 11 22 hello2 hello world
原文地址:http://blog.csdn.net/xu5025/article/details/42099369