Saturday, 16 August 2014

Access Specifier(public, protected, default and private)


Access Specifier -:-  Access specifier defines the accessibility of classes, methods and variables. There are four types of access specifier(public, protected, default, private) are provided in java programming language. By default, default is applied.

Public :- public means accessible and visible to every one in the package and outside the package. Classes, methods, constructors and variables can be accessed from every where.

Protected :- protected means accessible and visible to every one in the same package and only to sub-classes out side the package.

Default :- default is applied by default. It is package friendly. When we do not apply any access modifier than it is applied. It means accessible only in the same package.

Private :- private means accessible only to the same class. Methods, variables and constructors declared as private only visible to the same class.



No comments:

Post a Comment