java:1: error: class, interface, or enum expected Public class

java:1: error: class, interface, or enum expected Public class

In java:1: error: class, interface, or enum expected Public class we face this error when we misspell the keyword “Public” instead of “public”. To fix or solve the error, ensure you type the correct spelling in your code. In this case, you should replace Public (Capital P) with the public (Small P), and then rerun the code, for more clarification please see the below example.

Wrong Code

Public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
        
    }
}

Error Massage

HelloWorld.java:1: error: class, interface, or enum expected
Public class HelloWorld {
^
1 error
error: compilation failed

Wrong code line

Public class HelloWorld {

Correct code line

public class HelloWorld {
  • Incorrect spelling: Public (capital letter P).
  • Correct spelling: public (with small letter p).

Entire Correct Code line

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
        
    }
}

What is java:1: error: class, interface, or enum expected Public class?

In java, we face this error when we have written “Public” instead of “public”. In Java, the word “public” is a keyword that is used to specify the access level of a class, method, or field, in this scenario we need to spell it correctly.

How to fix java:1: error: class, interface, or enum expected Public class?

If you want to fix this error, ensure you type the correctly spell it in your code. In this case, you should replace Public (Capital P) with the public (Small P), and then rerun the code, for more clarification please see the above example.

For more information please visit YouTube Channel.

Scroll to Top
Top 7 Gaming Project In python Save ₹25,000 Laptop under ₹11,999 Top 7 Funny error in Python Unicodeescape Most dangerous error in Python Hero Electric Battery Price In 2023