![](/img/trans.png)
[英]Keep on getting a “Cannot find symbol” on my simple Java program and don't know why
[英]Why my program no work ? keep getting cannot find symbol error?
嘗試在主代碼中創建子類h對象時,我不斷遇到找不到符號錯誤的情況。 有人可以幫忙嗎? 謝謝。
似乎主程序正在接受inhtt對象,但是當我嘗試調用h對象時,它說它找不到符號並要求我創建h對象。
public class inhtt {
//class methods
public int thing;
public int stuff ;
public int otherstuff;
// constructor based on parameters
public inhtt( int x, int y, int z){
thing = x;
stuff = y;
otherstuff = z;
}
void showmain (){
System.out.println("thing is " + thing);
System.out.println("stuff is " + stuff);
System.out.println("otherstuff is " + otherstuff);
}
public class h extends inhtt {
int beard;
h( int x, int y, int z, int a){
super(x,y,z);
beard = a;
}
void shownewa(){
System.out.println("beard is" +beard);
}
}
}
* @author New User
*/
public class runraffharsh {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
inhtt base = new inhtt(1,1,1);
base.showmain();
h = new h(1,1,1,1);
h.shownew();
// raff beard = new raff(1,1,1,1);
// beard.showbeard();
//
}
}
此代碼存在多個問題:
h
是inhtt
的內部類。 由於它不是靜態的,因此您需要使用諸如base.new h(1,1,1,1);
類的東西base.new h(1,1,1,1);
實例化它。
您需要聲明一個變量以將新的h
實例分配給該變量。 嘗試類似inhtt.hh = base.new h(1,1,1,1);
對於整條線。
h
(該類)沒有名為shownew
方法。 它有一個名為shownewa
的方法。
runraffharsh
和inhtt
都是公共類。 它們需要放在單獨的文件中。
runraffharsh
頂部的注釋塊未正確打開。
您對繼承的類h的引用有疑問。 並且您定義了showewa(),但嘗試訪問showew()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.