[英]I cant run this program in eclipse but it works on JGRASP
I have the following code that makes an abstract class, concrete class that extends abstract class and a main method. 我有以下代码构成抽象类,扩展抽象类的具体类和主要方法。 There are no errors as it compiles and run fine in JGRASP. 没有错误,因为它可以在JGRASP中编译并正常运行。 when I run in eclipse, it is just not running, but no errors produced. 当我在Eclipse中运行时,它只是没有运行,但是没有产生错误。 I named the file Product.java. 我将文件命名为Product.java。
Here is the code: 这是代码:
abstract class Product {
int value;
public Product(int val) {
value = val;
}
abstract public int multiply(int n);
}
class TimesTwo extends Product {
public TimesTwo(int val) {
super(val);
}
@Override
public int multiply(int n) {
return value * n;
}
public static void main(String[] args) {
TimesTwo two = new TimesTwo(5);
System.out.println(two.multiply(5));
}
}
I also try to run on commandline: 我也尝试在命令行上运行:
javac Product.java
I get Product.class
and TimesTwo.class
我得到Product.class
和TimesTwo.class
and when I run Java TimesTwo.class
or Java Product.class
当我运行Java TimesTwo.class
或Java Product.class
I get Exception in thread "main" java.lang.NoClassDefFoundError:
我Exception in thread "main" java.lang.NoClassDefFoundError:
得到Exception in thread "main" java.lang.NoClassDefFoundError:
在Eclipse
运行之前,请确保TimesTwo.java
作为单独的Java源文件存在。
You should change TimesTwo
to public class
and try to run command as below: 您应该将TimesTwo
更改为public class
并尝试运行以下命令:
java TimesTwo
There is no .class
at the ending when running a class 运行课程时,结尾没有.class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.