Access Specifier or Modifiers
What is Specifiers
- It is a keyword which is used to provide accessibility of data member(variable) and member function(function) of a class.
- In another word in loop system to defines scope and visibility(Security) access modifier are defined, In defined the data-members of members function can be access from where or Not.
- It is also called access modifier.
The public is keyword is an access modifier, meaning that it is used to set the access level for classes, attributes, methods and constructors.
An Example of Public access in case of class.
Modifiers are divided into two types:
Table of Contents
Types of Access Specifier
Access Specifiers are divided into Four types.
1.Default: Automatically generated without any use access specifiers.
2.Public: No Security, can be access from any where in the program.
3.Private: Full Security, this case can't access from outside the class access inside.
4.Protected: Less Secure, can be access inside the class and relative class.
Default:-
- It is allow automatically generated without any use access specifiers but given value in my requirement.
- It is used in Classes Case.
- The class is only accessible by classes in the same package. This is used when you don't specify a specifiers, You will learn more about packages in the Packages chapter.
- Lets an example for better understanding.
- Well now this-day access version of 17,18... etc javaVer support default.
1. An Example For Classes Case used public types :
******Output*****
******Output*****
Access specifiers used in attributes, methods and constructors,
Public:-
- It allows the accessibility of data member and member function to the other classes.
- public element of a class can be accessed anywhere in the program.
- In Another Word:- It has no Security, that means public members can be provided to the interface to the external world so can be access from any where in the program.
- Lets see an example for better understanding.
******Output*****
Private:-
- 1.It is used to hide data member and member function from the other classes.
- 2.private element of a class can be accessed only inside in its own class. 3.private element of a class can not be accessed out of that class.
- In another word:- It is most important and secure members(private) can be access only inside the class or type of access out-side the class.
- To hide the data members input the in private area
- Lets see an example for better understanding.
******Output*****
Protected:-
- It is approximately same as private but it allows the accessibility of data member and member function to the child class.
- IN ANOTHER WORD:- It's less secure by private, protected members can be access by class member and by the members of derived class, that means we can say that protected members can be access inside the class and relatives class.
- Protected is used in the case of inheritance.
- Lets see an example for better understanding.
******Output*****
Non Access Specifiers :-
In this case we use with classes, methods, and attributes cases. There are many place we can use suppose that abstract, final, static many keywords are used this is more we can learn next chapter.
An Example of final Keywords:
******Output*****
I HOPE THIS IS HELPFUL FOR YOU THANK YOU.
Comments