File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dynamic Binding Doubt" Watch "Dynamic Binding Doubt" New topic

Dynamic Binding Doubt

Nitin Kasat

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

class A{
public void foo(String... a)

class B extends A{
public void foo(String a)
public static void main(String[] arr){
A a=new B();"test");

The result of running class B is

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
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.

My Techie Blog - Java Questions
Nitin Kasat

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

Joined: Oct 31, 2007
Posts: 100

<a href="" target="_blank" rel="nofollow">Use Real Words</a> <a href="" target="_blank" rel="nofollow">!!!Use Code Tags!!!</a> <a href="" target="_blank" rel="nofollow">Say Thanks</a><br />scjp6
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Please check your private messages regarding an important administrative matter.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Dynamic Binding Doubt
jQuery in Action, 3rd edition