What is a top level class in Java?

It’s simply any class that’s not a nested class. If your file is Foo.java, and your class is Foo, then it’s a top level class.

// in Foo.java:

public class Foo { // top level class

    public static class NestedBar { // nested class
    }

}

I had always thought this was an informal term, but it turns out it’s actually defined in the JLS:

A top level class is a class that is not a nested class.

A nested class is any class whose declaration occurs within the body of another class or interface.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)