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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:24:05+00:00 2026-05-13T12:24:05+00:00

Wikipedia on the diamond problem: … the diamond problem is an ambiguity that arises

  • 0

Wikipedia on the diamond problem:

“… the diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If a method in D calls a method defined in A (and does not override the method), and B and C have overridden that method differently, then from which class does it inherit: B, or C?”

So the diamond looks like this:

  A
 / \
B   C
 \ /
  D

My question is, what happens if there is no such class A, but again B and C declare the same method, say foo(). Isn’t this the same problem? Why is it then called diamond problem?

Example:

class B {
    public void foo() {...}
}

class C {
    public void foo() {...}
}

class D extends B, C {
}

new D().foo();
  • 1 1 Answer
  • 1 View
  • 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-05-13T12:24:05+00:00Added an answer on May 13, 2026 at 12:24 pm

    Its not the same problem.

    In the original problem, the overriden method can be called from A. In your problem this can’t be the case because it does not exist.

    In the diamond problem, the clash happens if class A calls the method Foo. Normally this is no problem. But in class D you can never know which instance of Foo needs to be called:

             +--------+
             |   A    |
             | Foo    |
             | Bar    |
             +--------+
                /  \
               /    \
              /      \
    +--------+        +--------+
    |   B    |        |   C    |
    | Foo    |        | Foo    |
    +--------+        +--------+
              \      /
               \    /
                \  /
             +--------+
             |   D    |
             |        |
             +--------+
    

    In your problem, there is no common ancestor that can call the method. On class D there are two flavors of Foo you can chose from, but at least you know that there are two. And you can make a choice between the two.

    +--------+        +--------+
    |   B    |        |   C    |
    | Foo    |        | Foo    |
    +--------+        +--------+
              \      /
               \    /
                \  /
             +--------+
             |   D    |
             |        |
             +--------+
    

    But, as always, you do not need multiple inheritance. You can use aggegration and interfaces to solve all these problems.

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

Sidebar

Related Questions

From Wikipedia : Generic programming is a style of computer programming in which algorithms
From Wikipedia, the free encyclopedia: Closure (computer science) In computer science, a closure is
http://en.wikipedia.org/wiki/Diamond_problem I know what it means, but what steps can I take to avoid
Wikipedia says SQL Server Express Edition is limited to one processor, 1 GB memory
Wikipedia says Ruby is a functional language, but I'm not convinced. Why or why
Wikipedia has this to say: Total functional programming (also known as strong functional programming,
Wikipedia provides a number of citations used in the sciences , however does one
Wikipedia allows you to reproduce its content. If you want to use Wikipedia materials
Wikipedia states: In practice, explicit right outer joins are rarely used, since they can
The wikipedia article about Law of Demeter says: The law can be stated simply

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.