class, interface, or enum expected – compilation error

In Java it is not necessary for a class to have package statement. But if it has then it has to be the first statement. The following class would give a compilation error as  “class, interface, or enum expected” as the package statement defined between import and the class definition.

import java.util.*;

package com;

public class Test {

public static void main(String args[]) {

System.out.println("Hello !!!");

}

}

C:ProjectsJavamyscjpchap1>javac Test.java

Test.java:3: class, interface, or enum expected

package com;

^

1 error

In Category: Java, SCJP

Ravi Shankar

A Software developer and blogger who is always looking to provide technical help to the wider community.

Show 2 Comments

Leave a Comment

Get your free copies of the following tech guides by joining the Digital Answers mailing list.