-6
爲什麼會出現此錯誤?請參閱下面的代碼。爲什麼這個類不編譯?
class Test{
Hello h=new Hello();
}
class Hello{
int a=10;
System.out.println(a); // error identifier expected
}
爲什麼會出現此錯誤?請參閱下面的代碼。爲什麼這個類不編譯?
class Test{
Hello h=new Hello();
}
class Hello{
int a=10;
System.out.println(a); // error identifier expected
}
用同一個包創建類
public class Hello {
public void print(){
int a = 10;
System.out.println("Number is :" +a);
}
}
木箱類設置的主要方法在hello方法的同一個包
public class Main {
public static void main(String args[]){
Hello h1 = new Hello();
h1.print();
}
}
你怎麼能指望這樣即使沒有主運行方法? –
很多這方面的錯誤。沒有main()函數。沒有任何塊的System.out函數。在Test中創建一個main()函數,並將靜態後的System out語句置於靜態。 – BeardAspirant