Access modifiers in java

Publicado em: 06 Junho 2023
no canal de: 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


Nesta página do site você pode assistir ao vídeo on-line Access modifiers in java duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Smart Engineer 06 Junho 2023, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 263 vezes e gostou 5 espectadores. Boa visualização!