Types of Access Modifiers

taxiongo

Member
Four Types of Access Modifiers:
1. Private: We can access the private modifier only within the same class and not from outside the class.
2. Default: We can access the default modifier only within the same package and not from outside the package. And also, if we do not specify any access modifier it will automatically consider it as default.
3. Protected: We can access the protected modifier within the same package and also from outside the package with the help of the child class. If we do not make the child class, we cannot access it from outside the package. So inheritance is a must for accessing it from outside the package.
4. Public: We can access the public modifier from anywhere. We can access public modifiers from within the class as well as from outside the class and also within the package and outside the package.
 
Back
Top