創建一個自定義的類我想在Java中創建自定義的類的對象,我創建,但它顯示一個錯誤......不知道爲什麼這個錯誤發生,請幫助我,因爲我開始學習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
請縮進代碼,什麼是錯誤? – 2012-04-13 06:29:44
什麼是錯誤?不要讓我們猜測。 – 2012-04-13 06:29:59
當問問題時請說明您看到的錯誤(當您試圖編譯代碼?當你運行它?)和錯誤的文本。請修改您的問題以包含此信息。 – David 2012-04-13 06:30:48