3 Access Modifier in OOP's
3 Access Modifier in OOP's
OOP Interview
modifiers in
object-oriented
programming
When to use
Instance Variables: Use private for class attributes to
protect them from outside modification
Internal Methods: Use private for methods that are only
meant to be used inside the class.
Find more
interview tips -> neetcode.io
protected
Protected
private
class only
classes, subclasses
protected members limit the access to the variable, method,
or constructor to the class or subclasses and (in some
languages) other classes in the same package or module.
When to use
Use protected when you want a variable or method to be
accessible to subclasses but not to classes outside the
parentage.
inherits
Find more
interview tips -> neetcode.io
public
protected
Public private
class only
classes, subclasses
every class
different packages
Find more
Level
possible
Find more