alright, I have been aware of private, protected, and public access modifiers but just this week I discovered that there is also the default access modifier in Java. In case none of the three p-- modifiers is mentioned in a method header or field declaration, they seem to have the default access modifier. My idea is that one should be aware of it but that it is not very necessary to use. Rather, a coder should always specify one of the p- modifiers for every method/field. or am I wrong? If yes, could anyone give me some idea why one would want to use a default modifier?

Each of the four access modifiers specifies a different range of permitted accesses.
http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
You first decide how wide the access permissions need to be, then that tells you which modifier is appropriate.

(IMHO the four choices have always seemed to me to be a bit of a mess - protected is less protected than default, and there's no modifier that allows access only from subclasses)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.