简体   繁体   中英

java compiling error in command prompt

Error: Main method not found in class volume, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend 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));
    }
}

Move your main method to volume class and make volume class public. You don't need class main .

删除类main {和},然后在Volume类中有一个main方法

Your program works fine. you just compile the main class and execute the main class.

Logically, the main method should be inside the class Volume. In spite of that, your code should have worked. But the real reason you are getting the error is because remember: in Java, the class names have to start with an uppercase.

Simply rename the class volume as Volume, and main as Main and it should work.

Please change your public class in your program. Then everything works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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