Рет қаралды 17,685
In this video of code decode we have explained what is access modifier in java which is commonly asked interview question in java
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
openinapp.co/u...
Course Description Video :
yt.openinapp.c...
Access Modifiers in java by Example
Access Modifiers in java with example and animations - Theory | java class modifiers | Public, Protected, Private, Default
- Java access modifiers (default, public, private and protected) let you say which files can see methods and variables.
Access Modifiers :
Public: If we class then we can use public.
Protected: Visible to the package and all sub classes. Protected keyword is used.
Private: only if that class needs that variable then we can use private.
The access modifiers in java are:
default, public, private and protected.
Java Protected is the most tricky of all the four. Public private protected are specified with keyword but default access modifier in java does not need any keyword explicitly.
This tutorials following questions:
how to use access specifiers in java with examples, live coding example
public private protected java makes variables secure in java. these access specifiers make life of programmers much easy to have more control over variable access.
public and private modifiers are opposite while protected modifier is complex and rolls over extending classes.
This video tutorial explains the concepts of Java Access Modifiers. I have explained the importance of access modifiers and also explained how public, default access modifiers work at class level. The access modifiers for members- public,protected, default and private have been explained and demonstrated with an example.
Java protected access modifiers or protected access modifier in java make sure that no other class in another package can access your protected variables who doesnot extend your class.
Though java protected keyword does allow all your classes in same package even if they dont extend your class in which variable is defined to be accessing your protected variable.
java private access modifier is the most restrictive access modifier as it does not allow any other class to access your variable.
java private and protected keywords we have covered. These are also called java class modifiers.