Trip, Maybe there are tricks or tips to remember them but this is so elementary and so much used (if not always) I shouldn't try to remember them by a trick. IMHO these basics have to be really understood thoroughly... but again, that's my opinion. Erik Dark [ February 13, 2002: Message edited by: Erik Dark ]
Do as much as possible excersice. that would help you much i think. Learning java is not only memorising but experience. And the experience come from the exercise that we have done. The more exercise the more experience we have (the more we learn). And I think the most important to learn java is Experience, that's all..
One of the things that always confused me, is that if you wanted to be REALLY picky, none of those things are "real" access modifiers. The only 'true' **access** modifiers are
public, private, protected (and package, or 'default')
final, static and abstract are also modifiers, but only static has 'access' ramifications in the sense of the other 'access modifiers', and then only if you look at it sideways. The modifiers you list are more architectural, in my mind. They describe qualities of the classes/methods/variables that they modify that are beyond mere 'access'.
final 'things' can't be changed. For variables, that means they are constant. Final methods can't be overriden and final classes can't be subclassed.
abstract can only be applied to methods and classes. It means that there is no implementation for the method or class which it is modifying. ** I've thought about that a bit more... There is implementation possible in an abstract class. But if any single method is abstract, then the whole thing (class) is abstract. So it might be better to think of it as: An abstract class cannot be instantiated. **
static means that the variable or method belongs not to an instance of the class, but rather to the class as a whole. So this implies that you don't need an instance to use a static variable or method. [ February 13, 2002: Message edited by: Mike Curwen ]
I don't think there is *anything* picky about pointing out that there are only 3 access modifiers: public, protected, and private. There are lots of other modifiers, but they are not "access modifiers." Only access modifiers modify the accessibility of a member.
Joined: Dec 16, 2001
I don't think there is *anything* picky about pointing out that there are only 3 access modifiers: public, protected, and private. How about the rest ? what modifiers are they ?
Joined: Jan 07, 2002
There's not always an either-or way of labeling things. There's overlapping set membership of lots of java terms. Like the concept of reserved words and keywords that seem to cause so much confusion. There are several ways of organizing the modifiers. First, by what they can modify: classes, constructors,fields, interfaces, and methods. Not all modifiers can be used together, and certain combinations aren't allowed either class modifiers : public protected private abstarct static final strictfp constructor modifiers : public protected private field modifiers: public protected private static final transient volatile interface modifiers: public protected private abstract static strictfp method modifiers : public protected private abstract static final synchronized native strictfp Notice how you see "public protected private" in all categories. That's because they serve to control what members can be accessed by another object in any given context; they are the access modifiers. That's why they get a special name as a group. But all of these keywords are called "modifiers" because they modify classes, constructors,fields, interfaces, or methods: abstract final native private protected public static synchronized transient volatile. [ February 14, 2002: Message edited by: Rob Ross ]
The way that I always understood it is: The access specifiers are: private, protected, public and default ("friendly" or "package") The access modifiers are: abstract and final Declaration modifiers: transient, volitile and synchronized Based on this "static" is not really a modifier at all. It is a definition of what a thing is - not how available it is. A static variable is a completely different thing than a member variable. It lives in a different place. It has a different lifecycle. etc. [ February 15, 2002: Message edited by: Cindy Glass ]
"JavaRanch, where the deer and the Certified play" - David O'Meara
Joined: Jan 07, 2002
Well, the JLS doesn't have a term "access specifier," but it does have the term "access modifier."
8.5.1 Access Modifiers The access modifiers public, protected, and private are discussed in �6.6. A compile-time error occurs if a member type declaration has more than one of the access modifiers public, protected, and private.
There are also several places in the JLS that include the static keyword in the definition of an access modifier:
(last sentance of 7.6) It is a compile-time error if a top level type declaration contains any one of the following access modifiers: protected, private or static.
8.1.1 Class Modifiers ...The access modifier static pertains only to member classes (�8.5, �9.5)...
But there is no term "access specifier" in the JLS.
Just to be clear - the term Access Specifiers is used all over in the Sun Tutorials. Ex: from The Java Tutorial
In Java, you can use access specifiers to protect both a class's variables and its methods when you declare them. The Java language supports four distinct access levels for member variables and methods: private, protected, public, and, if left unspecified, package.