aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes More specific??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "More specific???" Watch "More specific???" New topic
Author

More specific???

Sun LiWei
Ranch Hand

Joined: Aug 10, 2002
Posts: 49
class A {}
class B extends A {}
class C extends B {
static void m(A x, A y) {System.out.print("AA");}
static void m(A x, B y) {System.out.print("AB");}
static void m(B x, A y) {System.out.print("BA");}
static void m(B x, B y) {System.out.print("BB");}
public static void main(String[] args) {
m(null,null);
}
}
I know that m(null,null) calls m(B x,B,y) and my question is why m(B x, B y) is more specific than
m(A x, A y)???
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
I know that m(null,null) calls m(B x,B,y) and my question is why m(B x, B y) is more specific than
Because m(B x, B y) has arguments that more derived (specific) than m(A x, A y).
Barkat
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
The following quote is from theJava Language Specification, Section 15.12.2.2, Choose the Most Specific Method.
The informal intuition is that one method declaration is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: More specific???