Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:51:38+00:00 2026-06-10T06:51:38+00:00

I have a behaviour that I don’t understand with overloading in Java. Here is

  • 0

I have a behaviour that I don’t understand with overloading in Java.

Here is my code:

interface I {}

class A implements I {}

class B {
   public void test(I i) {}

   public void test (A a) {}
}

When I call the following line:

 I a = new A();
 b.test(a);

I thought the called method would be test(A) but visibly it’s test(I).

I don’t understand why. In runtime my variable a is a A even A inherits I.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:51:39+00:00Added an answer on June 10, 2026 at 6:51 am

    Because the reference type is of I eventhough you have object of type A.

    A a = new A();

    will invoke method test (A a) {}

    As per JLS Chapter 15:

    The most specific method is chosen at compile-time; its descriptor
    determines what method is actually executed at run-time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a question about a behaviour i don't quite understand: i have two
I have a weird behaviour that has only shown up in the last week.
I have seen behaviour in Perforce that I am unable to explain. I took
I am implementing view controllers that shall have different behaviour. They have a common
Say I have a number of trait s that each add some behaviour to
I understand the reasons for compiler/interpreter language extensions but why is behaviour that has
So that you don't have to read all of the below, the crux of
I have recently noticed that my test code is too close to the production
I'm trying to have all my views inherit from a custom class so that
I have developed a behavior that changes the Clip property of the AssociatedObject. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.