Access Modifiers With Example
Access Modifiers With Example
Java provides a number of access modifiers to set access levels for classes, variables,
methods, and constructors. The four access levels are −
boolean processOrder() {
return true;
}
Here, the format variable of the Logger class is private, so there's no way for other
classes to retrieve or set its value directly.
So, to make this variable available to the outside world, we defined two public
methods: getFormat(), which returns the value of format, and setFormat(String), which
sets its value.
The main() method of an application has to be public. Otherwise, it could not be called
by a Java interpreter (such as java) to run the class.
class AudioPlayer {
protected boolean openSpeaker(Speaker sp) {
// implementation details
}
}