abstract class base{ public int age=getNumber(100); static{ System.out.println('base static block'); } { System.out.println('base nonstatic block'); } static int sage=getNumber(50); base(){ System.out.println(age); System.out.println('base start'); draw();//會(huì)調(diào)用子類(lèi)覆蓋后的方法,這兒是0! System.out.println('base end'); } static int getNumber(int base){ System.out.println('base.getNumber int'+base); return base; } public void draw(){ System.out.println('base.draw'); }}public class initializeOrder extends base{ public int age=getNumber(1001); private int _radius=getNumber(10); static int sage=getNumber(250); static{ System.out.println('subclass static block'); } { System.out.println('subclass nonstatic block'); } initializeOrder(int radius){ _radius=radius; System.out.println(age); draw();//這兒是1000 System.out.println('initializeOrder initialized'); } public void draw(){ System.out.println('initializeOrder.draw '+_radius); } public static void main(String[] args) { // TODO Auto-generated method stub new initializeOrder(1000); }}
|
|