| Author |
keyword
|
Raj Gahalot
Greenhorn
Joined: Aug 07, 2008
Posts: 7
|
|
|
If you want subclasses to access, but not to override a superclass member method, what keyword should precede the name of the superclass method?
|
Raj<br />Preparing for SCJP1.5
|
 |
jean-gobert de coster
Ranch Hand
Joined: Dec 04, 2008
Posts: 49
|
|
Not sure I understand your question... do you mean: how can I guarantee that my object's subclasses don't override one of my methods, then you should use the "final" modifier in front of your method declaration. was that your question? [ December 16, 2008: Message edited by: jean-gobert de coster ]
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
just use public final. This will allow subclasses to access the member and not able to override it...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
victor kamat
Ranch Hand
Joined: Jan 10, 2007
Posts: 247
|
|
Use super.<methodName> [ December 16, 2008: Message edited by: victor kamat ]
|
 |
raj malhotra
Ranch Hand
Joined: Feb 22, 2007
Posts: 285
|
|
just use public final. This will allow subclasses to access the member and not able to override it...
To stop overriding 'final' is the alone keyword required in method definition.You can also use public,protected and default access modifier with it.
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
Originally posted by raj malhotra: To stop overriding 'final' is the alone keyword required in method definition.You can also use public,protected and default access modifier with it.
I wrote public final because of this statement in the original question
If you want subclasses to access
If you don't use public, then some sub-classes might not be able to access the member...
|
 |
 |
|
|
subject: keyword
|
|
|