-4
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
ItamarG3
  • 4,092
  • 6
  • 31
  • 44
Prajwal P K
  • 9
  • 1
  • 3

1 Answers1

0

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.

Mureinik
  • 297,002
  • 52
  • 306
  • 350