Why do i see 'error: class, interface, or enum expected' in java?

Example:

int x = 10;

public class Test {}

There's code outside the class definition that should be inside a class, interface, or enum.

Solution:

Place the code inside a class, interface, or enum definition.


public class Test {
    int x = 10;
}

Beginner's Guide to Java