| Author |
how to prevent overriding method?
|
dx wu
Ranch Hand
Joined: Apr 28, 2002
Posts: 60
|
|
hi,all: this is my question,Could someone tell me which is correct? thanks
|
 |
Inuka Vincit
Ranch Hand
Joined: Aug 10, 2004
Posts: 175
|
|
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)
|
MCP (C# application dev 70-316) 860<br />SCJP 1.4 100% SCJD (URLyBird) 378<br />MAD 100% nuts
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
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.
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Doyle Matt
Ranch Hand
Joined: Jul 05, 2004
Posts: 76
|
|
|
Good thing that when this kind of question appeared in my exam i answered it correctly.
|
SCJP 1.4
|
 |
Inuka Vincit
Ranch Hand
Joined: Aug 10, 2004
Posts: 175
|
|
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
Joined: Jul 11, 2001
Posts: 14112
|
|
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
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Vishnu Munnangi
Ranch Hand
Joined: Sep 28, 2004
Posts: 114
|
|
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
Joined: Aug 10, 2004
Posts: 175
|
|
dope
|
 |
Inuka Vincit
Ranch Hand
Joined: Aug 10, 2004
Posts: 175
|
|
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
|
 |
 |
|
|
subject: how to prevent overriding method?
|
|
|