Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to prevent overriding method?

 
dx wu
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,all:
this is my question,Could someone tell me which is correct? thanks
 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • 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)
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • 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.
 
Doyle Matt
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • 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
 
Vishnu Munnangi
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator


dope

 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic