• 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
[pastacode lang=”java” manual=”public%20class%20techy%20%0A%7B%20%20%20%20%20%0A%20%20%20%20%20%20%20%20public%20static%20void%20main(String%5B%5D%20args)%20%0A%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println(%22Hello%2C%20wikitechy!%22)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%09%0A” message=”java code” highlight=”” provider=”manual”/] [ad type=”banner”]

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.

Categorized in: