public class Test{
    public int i=0;
public static void main(String[] args){
System.out.print("hello!");
}
}
class test2
{
public void top()
{
i++;
}
}
出现的问题是:
F:\JAVA\Test.java:11: 找不到符号
符号: 变量 i
位置: 类 test2
                i++;
                ^
1 错误Process completed.
我有点想不通,应该怎样使i在class  test2()中可见?

解决方案 »

  1.   

    在 test2 中,实例化一个 Test
      

  2.   

    public class Test{
        public static int i=0;
    public static void main(String[] args){
    System.out.print("hello!");
    }
    }
    class test2
    {
    public void top()
    {
    Test.i++;
    }
    }
      

  3.   

    你没有理解面向对象,
    i相当于Test的属性 ,你没有对象怎么能调用它的属性那