我想在 JAVA 中创建一个自定义类对象并且我创建了但它显示错误...不知道为什么会发生此错误,请帮助我,因为我开始更早地学习 JAVA...
class main {
class student {
public int rollno;
public String name;
public int marks;
public void accept() {
rollno = 1;
name = "Pawan Mall";
marks = 100;
}
public void display() {
System.out.println(rollno);
System.out.println(name);
System.out.println(marks);
}
}
public static void main(String argv[]) {
student s = new student();
s.accept();
s.display();
}
}
它发生在编译时,这是我在编译代码时遇到的错误:
C:\Program Files\Java\jdk1.7.0_03\bin\student.java:28: error: non-static variable this cannot be referenced from a static context
student s = new student();
^
1 error
Tool completed with exit code 1