Are you even aware, that a top-level class may be non-public? That's the power of defaults, your IDE allows you to create a class with a single keystroke, and it merrily exposes the class for the whole world:

public class Underpants {
	private Color color = PINK;
}

Always use the lowest possible visibility, to promote encapsulation and high cohesion of packages:

class Underpants {
	private Color color = PINK;
}

And harness your IDE to help you with that – change the default visibility of newly created classes and methods to be package-private or private, and enable warnings about unnecessarily wide visibility.

W. Gdela

            Votes: 0

See more like this: