This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "the" fina"l and "static Watch "the" fina"l and "static New topic
Author

the" fina"l and "static'

lang lang
Greenhorn

Joined: Nov 01, 2003
Posts: 8
1. Which two declarations prevent the overriding of a method?(choose two.)
A. final void methoda () {}
B. void final methoda () {}
C. static void methoda () {}
D. static final void methoda () {}
E. final abstract void methoda () {}
Answer: A,C
would you tell me why ?
and would say something about final,static
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

Originally posted by lang lang:
1. Which two declarations prevent the overriding of a method?(choose two.)
A. final void methoda () {}
B. void final methoda () {}
C. static void methoda () {}
D. static final void methoda () {}
E. final abstract void methoda () {}
Answer: A,C
would you tell me why ?
and would say something about final,static

Because that's exactly what final keyword is designed for. When use for method it means the method is not overriable.
static keyword using on a method meant that the method belong to the Class,
not to the Object's instance. And Java language says what belong to the Class stays with the class and only belong to the class and not inherited.
Since the idea of overriding is to override inherited stuff, and static method is not inherited..by default it is not overriable. You can have the same method on the child class, but it is called shadowing..not overriding.
Hope that helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: the" fina"l and "static'
 
Similar Threads
Question on interface
explain this one .... i didnot understand it.
how to prevent overriding method?
how can we access a method from sub class from its super class?
overriding question required