Thursday, August 25, 2011

Basics: Java's public private protected default

public : Accesible everywhere. Any package. Any class.

private : Accessible only within the same class.

protected : Let class ABC declares something as protected. Then it is accessible to all classes in same package as ABC. Plus any class in any package, extending class ABC.

default : without any access modifier (ie, public private or protected).It means that it is visible to all within a particular package.

Note: A class class can be private or protected, ONLY if it is a Nested/Inner class, otherwise it has to be public (if top level class) OR default.

public class Test {

    private class NestedClass {

No comments:

Post a Comment