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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:59:52+00:00 2026-05-20T02:59:52+00:00

First of all… Sorry for this post. I know that there are many many

  • 0

First of all… Sorry for this post. I know that there are many many posts on stackoverflow which are discussing multiple inheritance. But I already know that Java does not support multiple inheritance and I know that using interfaces should be an alternative. But I don’t get it and see my dilemma:

I have to make changes on a very very large and complex tool written in Java. In this tool there is a data structure built with many different class objects with a linked member hierarchy. Anyway…

  • I have one class Tagged which has multiple methods and returns an object tag depending on the object’s class. It needs members and static variables.
  • And a second class called XMLElement allows to link objects and in the end generate a XML file. I also need member and static variables here.
  • Finally, I have these many many data classes which nearly all should extend XMLElement and some of them Tagged.

Ok ok, this won’t work since it’s only possible to extend just one class. I read very often that everything with Java is ok and there is no need for having multiple inheritance. I believe, but I don’t see how an interface should replace inheritance.

  1. It makes no sense to put the real implementation in all data classes since it is the same every time but this would be necessary with interfaces (I think).
  2. I don’t see how I could change one of my inheritance classes to an interface. I have variables in here and they have to be exactly there.

I really don’t get it so please can somebody explain me how to handle this?

  • 1 1 Answer
  • 4 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-05-20T02:59:53+00:00Added an answer on May 20, 2026 at 2:59 am

    You should probably favor composition (and delegation) over inheritance :

    public interface TaggedInterface {
        void foo();
    }
    
    public interface XMLElementInterface {
        void bar();
    }
    
    public class Tagged implements TaggedInterface {
        // ...
    }
    
    public class XMLElement implements XMLElementInterface {
        // ...
    }
    
    public class TaggedXmlElement implements TaggedInterface, XMLElementInterface {
        private TaggedInterface tagged;
        private XMLElementInterface xmlElement;
    
        public TaggedXmlElement(TaggedInterface tagged, XMLElementInterface xmlElement) {
            this.tagged = tagged;
            this.xmlElement = xmlElement;
        }
    
        public void foo() {
            this.tagged.foo();
        }
    
        public void bar() {
            this.xmlElement.bar();
        }
    
        public static void main(String[] args) {
            TaggedXmlElement t = new TaggedXmlElement(new Tagged(), new XMLElement());
            t.foo();
            t.bar();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all I have seen that there are many questions about unrecognized selector
First of all there is probably a question like this already but i couldn't
First of all, apologize because I have seen some posts about this, but I
First of all. I want to say that i've acctualy read the other posts
i have this code which i use in order to extract first all users
I have this code below, with which I select first all id's from table
First of all, I'm uploading multiple images that goes through a for loop by
First of all, I don't know if this should stay in SO or go
First of all, sorry if the title is misleading. This is literally my first
First of all sorry if this is really complicated to understand, but it is

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.