Access modifiers in java

Published: 06 June 2023
on channel: 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


Watch video Access modifiers in java online without registration, duration hours minute second in high quality. This video was added by user Smart Engineer 06 June 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 26 once and liked it people.