蓝森林首页 | 返回主页 | 本站地图 | 站内搜索 | 联系信箱 |
 您目前的位置:首页 > 自由软件 > 技术交流 > 应用编程


    

蓝森林 http://www.lslnet.com 2006年6月6日 10:18


#在一个类中不能引用另一个类中的Public变量问题!

举个小例子:
Test00与Test0位于同一包中
Test00:
import javax.swing.* ;
public class Test00 extends JFrame {
       
    Test0 test0 ;
    public Test00() {
        test0 = new Test0() ;        
        //test0.i
        JOptionPane.showMessageDialog( null ,
             String.valueOf( test0.i  )  ) ; [color=red]------->;此处为何得不到i的值[/color]
    }
   
    public static void  mian(  ) {
        Test00 test00 = new Test00() ;  
                test00.setSize( 200 , 300 ) ;
        test00.show() ;
        test00.setDefaultCloseOperation(  JFrame.EXIT_ON_CLOSE  ) ;
    }

}
Test0:
public class Test0 {
    public int i ;
    public Test0( ){
        i = 1 ;   
    }
}
郁闷!!!高手指点! :em14:

#在一个类中不能引用另一个类中的Public变量问题!

有Exception么?这个程序在我的机器上运行的挺好的。

#在一个类中不能引用另一个类中的Public变量问题!

啊 在我的机子上面就不行!用的是日文版的sdk
也不知道是什么异常!郁闷啊!!

#在一个类中不能引用另一个类中的Public变量问题!

sakulagi:
      是能对 i 进行是这样操作:test0.i= test0.i +163;吧?

#在一个类中不能引用另一个类中的Public变量问题!

public static void  mian(  )
应该这样:
public static void main(String[] args[])



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 蓝森林网站 版权所有。 E-mail : webmaster@lslnet.com