[英]could not find or load main class.java
我在Java中有兩個用於函數重載的類,即ABC和XYZ。 XYZ類具有函數重載方法,而ABC類具有main重載方法。 我已將文件另存為ABC.java。 該程序可以編譯,但是在運行時顯示錯誤“找不到或加載主類ABC”。 我還附上了具體的代碼。
class XYZ
{
void pqr(int a, int b)
{
int res = a*b;
System.out.println("The result is "+res);
}
void pqr(String a, String b)
{
System.out.println("The concatenated string is "+a+b);
}
void pqr(int a, int b, int c)
{
int res = a+b+c;
System.out.println("The final result is "+res);
}
}
class ABC
{
public static void main(String[] args)
{
XYZ a = new XYZ();
a.pqr(10,20);
a.pqr("Pratik","Paul");
a.pqr(20, 40, 60);
}
}
請按照以下步驟操作,
第1步:
go the bin folder of Java from command prompt(I assume you are trying to run the program from command prompt).
ex: C:\Program Files\Java\jdk1.8.0_05\bin
第2步:
javac <your ABC.java file with full path>
ex: javac C:\Test\ABC.java
similary do for XYZ.java
第三步:
Go to C:\Test\ from command prompt and run,
java ABC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.