Chinaunix

标题: non-static variable this cannot be referenced from a static [打印本页]

作者: tanghongfeng    时间: 2003-06-19 15:31
标题: non-static variable this cannot be referenced from a static
程序如下:import java.io.*;
class test1
{
public class data1
{
public  int day=0;
public  void print()
        {
                System.out.println("this is example";
        }
}
public static void main(String args[])
{
        data1 ab=new data1();
        ab.day=10;
        ab.print();

}
}

编译出错
[thf@server src]$ javac -classpath /home/thf test1.java
test1.java:14: non-static variable this cannot be referenced from a static contt
        data1 ab=new data1();
                 ^
1 error
作者: rollingpig    时间: 2003-06-19 16:40
标题: non-static variable this cannot be referenced from a static
你使用了内部类

不能在非外部类或者是static方法直接构造!!




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2