Java error – illegal start of type

When you compile a java program as shown below, you would get illegal start of type error. This is because the import statement is with in the class definition. Any import statement should be defined before the class definition and after the package statement (if package statement is declared for a class)

package com;

public class Test {

mport java.util.*;

public static void main(String args[]) {

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

}

}

Errors

C:ProjectsJavamyscjpchap1>javac Test.java

Test.java:4: illegal start of type

import java.util.*;

^

Test.java:4: ‘;’ expected

import java.util.*;

^

Test.java:4: illegal start of type

import java.util.*;

^

Test.java:4: ‘;’ expected

import java.util.*;

^

4 errors

In Category: Java, SCJP

Ravi Shankar

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

Show 0 Comments
No comments yet. Be the first.

Leave a Comment

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