我在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 FilesJavajdk1.8.0_05bin
步骤2:
javac <your ABC.java file with full path>
ex: javac C:TestABC.java
similary do for XYZ.java
步骤3:
Go to C:Test from command prompt and run,
java ABC