華為面試其中一題

0763lch發表於2003-03-08

請問高手,為什麼輸出結果是:

111

666

而不是

111

222

class BaseClass {

final static int x = 111 ;

public BaseClass()

{

System.out.println (" The value of x is " + x );

getVar ( ) ;

}

public void getVar ( ) { System.out.println (" The value of x is 222" );;}

}

public class Bean1 extends BaseClass

{

final static int x = 555 ;

public Bean1()

{ super();

}

public void getVar ( ) { System.out.println (" The value of x is 666" );;}

public static void main (String args[]){

Bean1 b=new Bean1();

}}

相關文章