public class OtherTest {
int IP=3;
public static void main(String[] args){

System.out.println(IP);
}}说不能对非静态字段IP进行静态引用,请问错误出在什么地方 ,是main里的必须用静态还是println里的用静态?

解决方案 »

  1.   

    木错。public class OtherTest {
    static int IP=3;//static add.try again.
    public static void main(String[] args){

    System.out.println(IP);
    }}
    或者
    public class OtherTest {
    int IP=3;
    public static void main(String[] args){
    OtherTest O=new OtherTest();//new ,try again.
    System.out.println(O.IP);
    }}
      

  2.   

    对,main函数是static函数,当然不能调用非static变量,要么在变量前加上static,直接调用,要么在main里面先实例化这个类的对象,再用这个对象来调用这个变量。
      

  3.   

    在static的方法里面所有的变量都是static的变量,它不能调用非静态的变量或者方法
      

  4.   

    那个是OtherTest 的私有数据成员啦,不管main的事情