Prajwal P K
Prajwal P K

Reputation: 9

Java compile expected public class error

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

while compiling it was showing error

---------- Compile ----------
Untitled1.java:1: error: <identifier> expected
public class  
            ^
1 error

Output completed (0 sec consumed) - Normal Termination

Upvotes: -4

Views: 6232

Answers (1)

Mureinik
Mureinik

Reputation: 311393

You're missing the name of the class:

public class MyFirstClass
// Here -----^
{
    public static void main(String[] args) 
    {
        System.out.println("Hello World!");
    }
}

Note that a public class' name must match the name of the file that declares it.

Upvotes: 0

Related Questions