• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

overriden method

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

according to me the ans is final & static
ans given is :final
pls help
thanks
sherin
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sherin,
The question says the subclass should "access" but no "OVERRIDE"
the superclass method. A method declared static can be overridden (actually hidden) by a static method.
When you declare a method as final, the subclass can access the method but u can't override it. Hence the ans is "final".
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I'd opt for just final.
But as far as static is concerned, static methods are implicitly final. Therefore they are not overridden only hidden
-sampaths77
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have confusion about sherin explanitions
writes
" A method declared static can be overridden (actually hidden) by a static method."
According to me
static method can't be overriding.
Am I right or wrong
Pankaj
gaur_p@hotmail.com
 
PANKAJ
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have confusion about sherin explanitions
writes
" A method declared static can be overridden (actually hidden) by a static method."
According to me
static method can't be overriding.
Am I right or wrong
Pankaj
gaur_p@hotmail.com
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JLS clearly says that static methods are implicitly final. Therefore they are not overridden only hidden.
Hope this help
sampaths77
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sheri:
If you want subclasses to access, but not to override a superclass member method, what keyword
should precede the name of the superclass method?

according to me the ans is final & static
ans given is :final
pls help
thanks
sherin


Hi Sherin,
the final key word acts like this,
a final class cannot be subclassed ie extended by another class,
a final method cannot be overidden and
a final variable ,once initialised ,cannot be assinged another value.
while static keyword will only make the method a class method instead of being an instance one.It does not ensure that the method will not be overidden.
vikas
------------------
bods
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic