Java Access Specifier

January 30, 2016 0 Comments

If other programmers use your class, you want to ensure that errors from misuse cannot happen. Access levels can help you do this.

Use the most restrictive access level that makes sense for a particular member. Use private unless you have a good reason not to.
Avoid public fields except for constants. (Many of the examples in the tutorial use public fields. This may help to illustrate some points concisely, but is not recommended for production code.) Public fields tend to link you to a particular implementation and limit your flexibility in changing your code.

| Class     |Package|Subclass | World
public | y | y | y | y
protected | y | y | y | n
Default | y | y | n | n
private | y | n | n | n

y: accessible
n: not accessible


Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google



Best Watch Store

Popular Posts

Contact Form


Email *

Message *