I am trying to write a program, but I'm getting this compiler error:
Main.java:1: error: class WeatherArray is public, should be declared in a file named WeatherArray.java
public class WeatherArray {
^
1 error
I have checked my file names, and my public class is the same as my .java file.
How can I fix this?
Here is my code:
public class WeatherArray {
public static void main(String[] args) {
// ...
}
}
java , so it doesn't need to go thru all packages ( which may contain multiple classes) it will now only search that package in which a source file A. java is present. So from compilation time , performance point if view one source file should have one public class.
The class interface or enum expected error is a compile-time error in Java which arises due to curly braces. Typically, this error occurs when there is an additional curly brace at the end of the program.
Name of public class must match the name of .java file in which it is placed (like public class Foo{}
must be placed in Foo.java
file). So either:
Main.java
to WeatherArray.java
public class WeatherArray {
to public class Main {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With