错误:在类卷中找不到主方法,请将main方法定义为:public static void main(String [] args)或JavaFX应用程序类必须扩展javafx.application.Application
import java.util.*;
class volume {
private int x;
public float volume(float l) {
return (l * l * l);
}
public float volume(float r, float h) {
return (3.14f * r * r * h);
}
public float volume(float l, float b, float h) {
return (l * b * h);
}
}
class main {
public static void main(String[] args) {
volume a = new volume();
System.out.println("volume of cube=" + a.volume(10));
System.out.println("volume of cylinder=" + a.volume(10, 10));
System.out.println("volume of cuboid=" + a.volume(10, 10, 10));
}
}
5 回答
将
main
方法移动到volume
类并将volume
类设为public . 你不需要class main
.删除类main {和}然后你将在Volume类中有一个main方法
你的程序工作正常 . 你只需编译
main
类并执行main
类 .从逻辑上讲,main方法应该在Volume类中 . 尽管如此,您的代码应该有效 . 但是你得到错误的真正原因是因为记住:在Java中,类名必须以大写字母开头 .
只需将类卷重命名为Volume,将main重命名为Main即可 .
请在您的计划中更改您的公共课程 . 一切正常 .