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 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

Wikipedia says: Selection algorithms: Finding the min, max, both the min and max, median
Wikipedia describes the Single Responsibility Principle this way: The Single Responsibility Principle states that
Wikipedia says that A piece of code is said to be exception-safe, if run-time
Wikipedia states that the Specification Pattern is where business logic can be recombined by
From Wikipedia : Where is said Local repository located physically (in the file system)?
Wikipedia says that locale dictates a set of formatting rules for a specific language/region
From http://en.wikipedia.org/wiki/Stack_pointer#Structure I am wondering why the return address for a function is placed
This is from wikipedia: http://en.wikipedia.org/wiki/Arraylist under Performance . ArrayList: constant time for remove(), add()
The following definition from wikipedia explains what is the Data Access Layer in a
Wikipedia states that a Deterministic State Automation produces a unique computation (or run) of

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.