Java Method Overloading Resolution by Declared Type
Given: What is the result? - 
Community Votes
100% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
The question tests static binding for overloading; the common trap is assuming dynamic dispatch (runtime polymorphism) applies to overloaded methods rather than overridden ones.
This Java 17 exam question tests the rule that method overloading is resolved at compile time based on the declared type of arguments, not their runtime types. The correct answer is B because the compiler binds calls to Animal and Dog signatures respectively.
Learners often choose C or E, mistakenly applying runtime polymorphism rules where they do not apply, leading them to believe the actual object instance determines which overloaded method is called.
Community Discussion (4 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
The code demonstrates method overloading, where multiple methods share the same name but have different parameter types. In Java, the decision of which overloaded method to invoke is made at compile time based strictly on the declared type of the variable passed as an argument. Since the variables are declared asAnimal and Dog, the compiler selects the runs(Animal) and runs(Dog) versions respectively, producing "runsflips".Why the Other Options Are Wrong
Option A is incorrect because it assumes both calls resolve to the base class version. Option C is a common distractor resulting from confusing overloading with overriding. Option D is wrong because the code is syntactically valid. Option E would only be correct if both arguments were treated as the most specific subclass, which violates Java's overload resolution rules.Community Comment Notes
The community consensus correctly identifies B as the answer. As user SrinivasJasti noted, "The compiler decides which method to call based solely on the declared type... This applies to both static and instance methods." User xplorerpj confirmed this by testing in IntelliJ, validating that the output matches the theoretical explanation.Exam Strategy
Always distinguish between Overloading (compile-time/dispatched by signature) and Overriding (runtime/dispatched by object type). If the method signature differs, look at the variable declaration. If the signature is identical, look at the object instance.
Frequently Asked Questions
Does the runtime type matter for overloaded methods?
No. Overloaded methods are resolved at compile time based on the declared parameter types, regardless of the actual object instance.
Why is 'Compilation fails' incorrect here?
The code is valid Java. The compiler can clearly distinguish between the two runs methods by their argument types Animal and Dog.