aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question on method overriding vs name reuse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question on method overriding vs name reuse" Watch "question on method overriding vs name reuse" New topic
Author

question on method overriding vs name reuse

Bob CHOI
Ranch Hand

Joined: Nov 10, 2006
Posts: 127
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 ]

Hard work rewards
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Bob CHOI
Ranch Hand

Joined: Nov 10, 2006
Posts: 127
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question on method overriding vs name reuse