aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "keyword" Watch "keyword" New topic
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
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

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
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: keyword