This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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


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.
 
GeeCON Prague 2014
 
subject: the" fina"l and "static'