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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:39:46+00:00 2026-06-15T13:39:46+00:00

I have a question like this : Think a scenario like this public class

  • 0

I have a question like this :

Think a scenario like this

public class Animal {

    protected String Name;
    Boolean canWork;

}

public class Dog {

  Enum TailType

}

And I need to have both of this classes attributes in a class of the third level which extends the both classes .. but using interfaces I don’t think this can be achieved. Is it possible to do this using a design pattern or some else method ?

Summary : I want to have attributes from two classes to a concrete class

  • 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-15T13:39:47+00:00Added an answer on June 15, 2026 at 1:39 pm

    You can have Dog extend Animal, then extend Dog by the third class, but unless your 3rd class is Poodle then you may have a problem you don’t realize yet. That being inheritance is only appropriate when the relationship is a modeling criteria, and extending objects only to get their functionality is the wrong approach. Inheritance should follow the IS-A principle. That being your subclass IS-A base class in modeling terms. If it doesn’t pass that test you are using inheritance when you shouldn’t. After all you can use delegation to obtain their functionality. That meaning:

    public class SomeClass {
    
        private Dog dog;
    
        public void bark() {
           dog.bark();  // this is reusing the functionality without extending
        }
    }
    

    Now SomeClass can call or invoke methods on Dog without extending it. Now the downside to this is a reference to Dog can’t point to SomeClass, but if SomeClass is-not-a Dog that’s probably good. However, if you have to allow Dog and SomeClass to share some typing so you can have a reference that points at either Dog or SomeClass then you can create an interface that both share:

    public class SomeClass implements Barkable {
        private Dog dog;
    
        @Override
        public void bark() {
           dog.bark();
        }
    }
    
    public class Dog implements Barkable {
    
        @Override
        public void bark() {
           System.out.println( "Bark! Bark!" );
        }
    }
    

    With delegation/composition and interfaces you DON’T need multiple inheritance. It’s a really simple technique to apply and master and you’ll build systems that are much more flexible than relying on inheritance alone.

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

Sidebar

Related Questions

I have a classic Order -> Order Row scenario something like this: public class
I have this scenario: class A { public virtual int Id { get; set;
I have a model that looks something like this: public class SampleModel { public
I have the same question like this: Delay before showing the tooltip I need
My question like this: I have a JTable, I put a JProgressBar in one
Kind of like this question I have many text snippets that I use many,
I have a question. My database table is something like this: | ID |
I have a question. I have plotted a graph using Matplotlib like this: from
I have a table which is currently displayed like this: Question OptionType What is
Absolute beginner question: I have a template file index.html that looks like this: ...

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.