Access Modifiers Flashcards
4 different types of access modifiers in least to most restrictive order
public
protected
default
private
can classes and interfaces be private
no
what does it mean when a variable is private
hidden from the outside world
from where can private variables be accessed
within the class it was declared
how can private variables be accessed from outside its declared class
using access modifiers
where are default variables available
to any other class in the same package
what is a package
a collection of classes
can protected be used on a class
no
what can protected be used on
variables, constructors, methods
what are public variables accessable to
any other class in the same package
with regard to objects, where can public attributes be accessed
anywhere in the program that has a reference to the objevt
with regard to objects, where can private attributes be accessed
only within the class itself
with regard to objects, how can protected attributes be accessed
within the class and any subclasses
are setters and getters needed with protected variables in classes
no