• Post Reply Bookmark Topic Watch Topic
  • New Topic

question on method overriding vs name reuse  RSS feed

 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code below,



Compilation failed because of being concieved of overriding between static and instance methods.

BUT, the inherited methods in A don't seem to be ambiguous with those in B.

//1 invoking instance method doo1() -> clearly, doo1() in A
//2 invoking static method doo2() -> clearly, doo2() in A
//3 invoking static method doo1() -> clearly, doo1() in B
//4 invoking instance method doo2() -> clearly, doo2() in B

Why would the compiler think it's about to override than name resue???

[ December 17, 2006: Message edited by: Bob CHOI ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether or not this compiles has nothing to do with main(). You can't override an instance method with a static method. End of story. Whether or not calls to the methods would be ambiguous or not is beside the point.
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure,

- static method can't be overridden by static method, but the static method name can be reused by static method in subclass
- static method can't be overridden by instance method, but why can't the static method name be resued by instance method in subclass?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!