• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

keyword

 
Raj Gahalot
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want subclasses to access, but not to override a superclass member method, what keyword should precede the name of the superclass method?
 
jean-gobert de coster
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just use public final. This will allow subclasses to access the member and not able to override it...
 
victor kamat
Ranch Hand
Posts: 247
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use super.<methodName>
[ December 16, 2008: Message edited by: victor kamat ]
 
raj malhotra
Ranch Hand
Posts: 288
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic