25. What are access modifiers ?

Modifier

Used with

Description

public

Outer classes, interfaces,

constructors, Inner classes, methods and field variables


A class or interface may be accessed from outside the package. Constructors, inner classes, methods and field variables may be accessed wherever their class is accessed.

protected

Constructors, inner classes, methods, and field variables.


Accessed by other classes in the same package or any

subclasses of the class in which they are referred (i.e. same

package or different package).


private

Constructors, inner classes,

methods and field variables


Accessed only within the class in which they are declared


No modifier

Outer classes, inner classes,

interfaces, constructors, methods, and field variables


Accessed only from within the package in which they are

declared.




No comments:

Post a Comment