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


On this page of the site you can watch the video online Access modifiers in java with a duration of hours minute second in good quality, which was uploaded by the user Smart Engineer 06 June 2023, share the link with friends and acquaintances, this video has already been watched 263 times on youtube and it was liked by 5 viewers. Enjoy your viewing!