繁体   English   中英

找不到或加载主类.java

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM