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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:06:53+00:00 2026-05-25T17:06:53+00:00

In many books it is written that interfaces are a replacement of multiple inheritance,

  • 0

In many books it is written that interfaces are a replacement of multiple inheritance, but I don’t find any similarity between both of them.

Inheritance is mostly important for re-usability of code and functionality and multiple inheritance was helping to re-use code from more than one class, but in interface I didn’t find any such feature except that a class can inherit from more than one interface.

Interface is just declaration of functions/methods and it didn’t contain any implementation part by itself, so class which are inheriting this interface should have to write their own implementation code.

So I don’t feel any re-usability of code in case of interface.

Is any document or link which will clear my doubts with you answer please share.

  • 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-05-25T17:06:54+00:00Added an answer on May 25, 2026 at 5:06 pm

    Regarding reusability of code, you are right. In that respect, multiple interfaces are no replacement of multiple inheritance.

    However, there’s another aspect of inheritance: it establishes an is-a relasionship between the base- and sub-class. So a class inheriting multiple super-classes can act as any of them. In this respect, interfaces serve as a valid replacement, e.g. a method accepting an interface will also accept any class implementing that interface, in the same way as a method will accept any class derived from the excpected class. But as you stated, each class has to implement the interface methods by their own.

    Example:

    public interface Foo {
        int doFoo();
    }
    
    public interface Bar {
        long doBar();
    }
    
    public class Baz {
        String doBaz() {
            return "This is baz";
        }
    }
    
    public class FooBar extends Baz implements Foo, Bar {
        public long doBar() {
            return 123;
        }
        public int doFoo() {
            return 456;
        }
    }
    
    // Accepts interface Bar implementing objects
    public void doSomething(Bar b) {
        System.out.println(b.doBar() * 10);
    }
    
    // Accepts interface Foo implementing objects
    public void doSomethingOther(Foo f) {
        System.out.println(f.doFoo() / 10);
    }
    
    // Accepts objects of class Baz and subclasses
    public void doMore(Baz b) {
        System.out.println(b.doBaz());
    }
    
    void bla() {
        FooBar fb = new FooBar();
    
        // FooBar can act as Foo, Bar, and Baz
        doSomething(fb);
        doSomethingOther(fb);
        doMore(fb);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is taught in every computer science class and written in many books that
Does anyone have any books written for .net that deal with multithreading? I've looked
While many ask questions about where to find good books or tutorials, I'd like
I'm reading about threads and in many books is said that Java support threads
I'd like to create an SQL statement that will tell me how many books
One thing that really interests me that I don’t see much written about or
Many books on SQL Server and even BOL mention that SQL Server uses B-tree
In many books or articles u may see such a definition about interface :
Each book can have many authors. And each author can author many books. class
Are Java final methods automatically inlined? Many books says yes many books says no!!!

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.