This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dynamic Binding Doubt 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 "Dynamic Binding Doubt" Watch "Dynamic Binding Doubt" New topic
Author

Dynamic Binding Doubt

Nitin Kasat
Greenhorn

Joined: Apr 07, 2008
Posts: 13
Hi All,
Following is the code snippet.

class A{
public void foo(String... a)
{
System.out.println("A:foo");
}
}

class B extends A{
public void foo(String a)
{
System.out.println("B:foo");
}
public static void main(String[] arr){
A a=new B();
a.foo("test");
}
}

The result of running class B is
A:foo

According to dynamic binding concept, as there is exact match with String parameter in class B output should be B:foo. Because compiler first searches for exact match then widening,boxing and at last var-args. But when I run it on eclipse I got this output.Can anybody clarify me on this output?


SCJP 5.0, SCWCD 5.0, SCBCD 5.0
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
Hi
The func foo() which is written in Class B is overloaded and not overriden. So for overloaded function are identfied by the instance of compile type object and not run time object.


<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
Nitin Kasat
Greenhorn

Joined: Apr 07, 2008
Posts: 13
Thanks Harshit. Now I got it.
Ivan Ivanic
Ranch Hand

Joined: Oct 31, 2007
Posts: 100
func???


<a href="http://faq.javaranch.com/java/UseRealWords" target="_blank" rel="nofollow">Use Real Words</a> <a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">!!!Use Code Tags!!!</a> <a href="http://faq.javaranch.com/java/SayThanks" target="_blank" rel="nofollow">Say Thanks</a><br />scjp6
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"yggdrasill",
Please check your private messages regarding an important administrative matter.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
Don't get me started about those stupid light bulbs.
 
subject: Dynamic Binding Doubt