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 7958423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:25:13+00:00 2026-06-04T04:25:13+00:00

Lets say I have this: class A { } class B : A {

  • 0

Lets say I have this:

class A { }
class B : A { }
class C : B { }

class Foo
{
    public void Bar(A target) { /* Some code. */ }
}

class AdvancedFoo : Foo
{
    public void Bar(B target)
    {
        base.Bar(target);
        // Some code.
    }
}

sealed class SuperiorFoo : AdvancedFoo
{
    public void Bar(C target)
    {
        base.Bar(target);
        // Some code.
    }
}

Which overload will be called if I run new SuperiorFoo().Bar(new C()) and why?
I’m guessing it will be called cascadely but I can’t figure out why and if that behavior is guaranteed.

UPDATED

So, the base. works with both Foo and AdvancedFoo for SuperiorFoo, so which one will be called and why?

  • 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-04T04:25:14+00:00Added an answer on June 4, 2026 at 4:25 am

    Edited my answer now that the question has been revised.

    A quick trace shows the following:

    Entering SuperiorFoo.Bar()
    Entering AdvancedFoo.Bar()
    Entering Foo.Bar()
    Leaving Foo.Bar()
    Leaving AdvancedFoo.Bar()
    Leaving SuperiorFoo.Bar()
    

    Lets talk through what happens:

    1. SuperiorFoo.Bar() calls its base method. Since SF.Bar() inherits
      from AdvancedFoo, its base method is AdvancedFoo.Bar().

    2. AdvancedFoo.Bar() then calls its base, which is Foo.Bar() since
      AdvancedFoo inherits from Foo().

    The process flow does NOT jump from SF.Bar() to Foo.Bar() because you could potentially want behaviour from the intermediate class.

    If we remove the method from AdvancedFoo, the traversal is slightly different. SuperFoo.Bar() will still call its base method, but since AdvancedFoo doesn’t hide the Foo.Bar() method anymore, the logic will jump to the Foo.Bar() method.

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

Sidebar

Related Questions

Lets simplify. Lets say I have this class: class Foo { public string Name
Lets say I have a class like this: public class Foo { public Foo
Lets say have this immutable record type: public class Record { public Record(int x,
Lets say i have this usercontrol public class test : UserControl { public int
Lets say I have this code: <?php class hello { var $greeting = hello;
lets say I have my owndefined datatype like this: public class InformationType { private
Let's say I have a simple POJO class: public void Foo { public int
Lets say I have the following code: public class Collection implements CollectionInterface{ ElementInterface[] elementArray
Lets say I have a class like this in Java: public class Function {
Let's say I have this code: class Score { public Update(int score) { update

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.