Ads

Wednesday, 21 March 2018

Access Modifiers || Access Specifiers in Java


Access Modifiers



Java Access Specifiers regulate access to classes, fields, and methods in Java.These Specifiers determine whether a field or method in a class can be used or invoked by another method in another class or sub-class.

There is main following access specifier in java.

1). Public 
2). Protected
3). Private

Public

When a member is defined by public specifier, it can be accessed from anywhere in the program. The "public" keyword is used to declare a member as public.

Protected

This access specifier is used in inheritance only. The protected members can be accessed only by its subclass. Protected keyword is used to declare the member as protected.

Private

When a member is defined by private specifier it can be accessed only the member of its class. The "private" keyword is used to declare a member as private.


When you do not specify any access specifier, the default specifier is applied to that member. The default access specifier work like as public access specifier
The default visibility is known as “private package” (though you can't use this explicitly)
Post a Comment

Click Here