• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the" fina"l and "static'

 
lang lang
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic