Home>

class InfoWeather {
static int month;
static int day;
static String sky;

}
class DateInfo {
public static void main (String args []) {
InfoWeather.month = 8;
InfoWeather.day = 10;
InfoWeather.sky = "rain";
System.out.println (InfoWeather.month + "month" + InfoWeather.day + "day" + InfoWeather.sky);
}
}
I put it like this and ran it, but I can not find the main (String []) method in the class in the terminal: InfoWeather It is written and I do not know where to fix so please reply!

  • Answer # 1

    Did you see the error and run it without compiling the source file?
    >java DateInfo.javaIf you run it without compiling, it will try to call the main () method for the first written class.
    Therefore, even if you try to call the DateInfo class, the InfoWeather class that does not have a main () method is called, and the error that the main () method cannot be found is displayed.

    It's recommended to compile and run it, but if you want to run it directly, move the class you want to run to the top of the file.

    class DateInfo {
        public static void main (String args []) {
            InfoWeather.month = 8;
            InfoWeather.day = 10;
            InfoWeather.sky = "rain";
            System.out.println (InfoWeather.month + "month" + InfoWeather.day + "day" + InfoWeather.sky);
        }
    }
    class InfoWeather {
        static int month;
        static int day;
        static String sky;
    }

  • Answer # 2

    As the error message says,InfoWeatherIn classmainThere is no method.

    File nameDateInfo.javaChange toDateInfoofmainLet's make it read when loading.

    (Note that you should only write one class per file in Java, except for very simple examples and nesting classes)