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

  • SEARCH
  • Home
  • 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 8037895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:03:41+00:00 2026-06-05T03:03:41+00:00

I can surely answer to this question by myself writing a dummy test but

  • 0

I can surely answer to this question by myself writing a dummy test but I want to know what people think about the question. Here it is:

Which method will be call when we have both at the same time overloading and overriding? I am only considering Type overloading and not arity overloading and when Type the overload are related.

Let me throw you an example:

class AA {}
class BB : AA {}

class A {
    public virtual void methodA(AA anAA) { Console.Write("A:methodA(AA) called"); }
    public virtual void methodA(BB aBB) { Console.Write("A:methodA(BB) called"); }
}

class B : A {
    public override void methodA(AA anAA) { Console.Write("B:methodA(AA) called"); }
}

new B().methodA(new BB());     // Case 1
new B().methodA(new AA());     // Case 2
new B().methodA((AA)new BB()); // Case 3

Can you tell what will happen in case 1, 2, and 3?

I personally think that overloadaing is evil and that there is no consistent thinking that could lead to a predictable answer. And that is completely base on a convention implemented in the compiler+vm.

EDIT: If you have some doubt about why overload is evil you can read the blog post from Gilad Brach

Thanks

  • 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-05T03:03:42+00:00Added an answer on June 5, 2026 at 3:03 am

    Overridden methods are excluded from method set when compiler determines which method to call. See member lookup algorithm. So, when you call methodA on type B, set of members with name methodA from type B and it’s base type will be constructed:

    override B.methodA(AA)
    virtual A.methodA(AA)
    virtual A.methodA(BB)
    

    Then members with ovveride modifier removed from set:

    virtual A.methodA(AA)
    virtual A.methodA(BB)
    

    This group of methods is the result of lookup. After that overload resolution applied to define which member to invoke.

    1. A.methodA(BB) is invoked, because its argument matches parameter.
    2. A.methodA(AA) will be chosen, but it is virtual method, so actually call goes to B.method(AA)
    3. Same as option 2
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This surely is a noob question, but I can't find an answer in Doxygen
Apologies for this seemingly minor question, but I can't seem to find the answer
I can't believe I'm asking this, but can't find a clear answer about it.
Surely this is a newb question as I am just learning RoR and can't
I think the answer to this question is so obivous that noone has bothered
I have a question that must surely seem very trivial, but the answer has
Surely I can add a parameter like add($pid). and call like control/add/4. But when
Simple question here that I can't seem to find an answer for: Once a
I know the question is very subjective. But I cannot form the question in
I have searched through google and SO for possible answers to this question, but

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.