Access modifiers in java

Veröffentlicht am: 06 Juni 2023
auf dem Kanal: Smart Engineer
263
5

Follow me on Instagram
  / smart_engineer_youtube  
There are mainly 4 access modifier
public , private, default and protected
01:20 public modifier
03:10 private modifier
03:52 default modifier
05:00 protected modifier

if we are giving public as the access modifier to variables or methods then it can be accessed from everywhere
if we are giving private as the access modifier for variable then only the class where variable is declared will be able to access it. No other classes will be able to access it.
if we are not giving any modifier then by default it will be a default modifier - if we use default modifier then it can be accessed from all the classes in the same package
if we are giving protected modifier then it works same like default that means we can access the variable in any classes of the same package

Subclass or child class also will be able to access protected variable.
protected = default + child class
we need to create child class reference to access the variable

if some other classes need to use private variable then we need to use getter and setter method.

java access modifier
access modifiers in java


Auf dieser Seite können Sie das Online-Video Access modifiers in java mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Smart Engineer 06 Juni 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 263 Mal angesehen und es wurde von 5 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!