ACCESS MODIFIERS ?

There are four access modiers

■ public
■ protected
■ default
■ private


PUBLIC-
When a method or variable member is declared public, it means all other classes,
regardless of the package they belong to, can access the member (assuming the class
itself is visible).
PRIVATE-
Members marked private can't be accessed by code in any class other than the
class in which the private member was declared.
DEFAULT AND PROTECTED-
Default protection is what you get when you don't type an access modifier in the
member declaration.
The default and protected access control types have almost identical behavior, except for one difference that is we can access protected variable in sub class in different packege where as for default it is not possible, it can be accessed only inside the same package,

A class can use just two of the four access control levels (default or
public), members can use all four.
local variables can have only default access.

No comments:

Post a Comment