- When the class name and the filename of a given Java program doesn’t match then we will get this error.
- Considering an example where the file is named as wiki.java
1 error found:
File: wiki.java [line: 1]
Error: class techy is public, should be declared in a file named wiki.java
- Since wiki does not match with techy, the code will not compile properly. To fix this error kind of error, either we need to rename the file or change the class name as “wiki.java”
- As the error message suggests, if we declare a class as public, it needs its wiki.java file. If we don’t want to do that, we don’t define it as public.