• 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

how to prevent overriding method?

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,all:
this is my question,Could someone tell me which is correct? thanks
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by net dongxiao:
hi,all:
this is my question,Could someone tell me which is correct? thanks



only the final keyword will prevent inheritance.
therefore A,D are correct
B is syntatically wrong, so is E cant have final and abstract togther, static methods can be overriden but, its called hiding since the behavior is different(its not exactly overriding)
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

static methods can be overriden but, its called hiding since the behavior is different(its not exactly overriding)



NO Inuka! You better give 1.6% back to Sun

Static methods cannot be overidden, they can only be hidden.
The final attribute also prevents hiding of static methods.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good thing that when this kind of question appeared in my exam i answered it correctly.
 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Barry Gaunt:


NO Inuka! You better give 1.6% back to Sun

Static methods cannot be overidden, they can only be hidden.
The final attribute also prevents hiding of static methods.




Hmm but isnt hiding a type of overriding , meaning you can declare a method in the class that inherits the parent with the same signature, thats how I understood the question. But you are right thats why I said it is hiding above.
Even in the spec they talk about each in the same breath


java spec

If a method declaration overrides or hides the declaration of another method....

so.... what is correct?
These types of questions realy confused the hell out of me when I did practice tests. Because some practice tests sometimes refereed to hiding as overriding.. and thats without considering the confusion with inner class terminology. Forutnately for me the real thing was very clear...(can I have my 1.6% back pleeeeaaaase )

sorry Net... not trying to confuse you...
[ October 03, 2004: Message edited by: Inuka Vincit ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Inuka Vincit:
Hmm but isnt hiding a type of overriding



No: http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#227927 and http://java.sun.com/docs/books/tutorial/java/javaOO/override.html
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

So what do you feel is the correct answer to the question

which two declarations prevent the overriding of a method?
A. final void methoda(){}
B. void final methoda(){}
C. static void methoda(){}
D. static final void methoda(){}
E. final abstract void methoda(){}
Thanks in advance..
 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ilja Preuss:


No: http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#227927 and http://java.sun.com/docs/books/tutorial/java/javaOO/override.html



dope

 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vishnu priya parimi:
Hi all,

So what do you feel is the correct answer to the question

which two declarations prevent the overriding of a method?
A. final void methoda(){}
B. void final methoda(){}
C. static void methoda(){}
D. static final void methoda(){}
E. final abstract void methoda(){}
Thanks in advance..





What Barry said.
A, C, D
I am going to shutup now
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic