Access Modifiers in Oops?

Access Modifiers in Oops

  • Access Modifiers also known as Visibility Specifiers.
  • Access Specifiers can be used to restrict access.
In other words, Access Modifiers are used to define the visibility of each aspect like class, variables(fields), methods, etc.. in Object-Oriented Programming Languages.
We can specify the visibility of class, variables, and methods using access modifiers or you can say simply, access modifiers are used to define the restriction or visibility of classes, fields, and methods.

There are three main types of access modifiers.
  1. Public -: The fields and methods can be accessed from everywhere. This is the default in PHP.
  2. Protected -:The fields and methods can be accessed within the class and by classes derived from that class.
  3. Private -: The fields and methods can only be accessed within the class.
NOTE-: Public, Private, and Protected not applicable with class in PHP.

No comments