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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:34:12+00:00 2026-05-16T15:34:12+00:00

I am reading The Java Tutorial (for the 2nd time). I just got through

  • 0

I am reading “The Java Tutorial” (for the 2nd time). I just got through the section on Interfaces (again), but still do not understand how Java Interfaces simulate multiple inheritance. Is there a clearer explanation than what is in the book?

  • 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-16T15:34:13+00:00Added an answer on May 16, 2026 at 3:34 pm

    Suppose you have 2 kinds of things in your domain : Trucks and Kitchens

    Trucks have a driveTo() method and Kitchens a cook() method.

    Now suppose Pauli decides to sell pizzas from the back of a delivery truck. He wants a thing where he can driveTo() and cook() with.

    In C++ he would use multiple inheritance to do this.

    In Java that was considered to be too dangerous so you can inherit from a main class, but you can “inherit” behaviors from interfaces, which are for all intents and purposes abstract classes with no fields or method implementations.

    So in Java we tend to implement multiple inheritance using delegations :

    Pauli subclasses a truck and adds a kitchen to the truck in a member variable called kitchen. He implements the Kitchen interface by calling kitchen.cook().

    class PizzaTruck extends Truck implements Kitchen {
       Kitchen kitchen;
    
       public void cook(Food foodItem) {
          kitchen.cook(foodItem);
       }
    }
    

    He is a happy man because he can now do things like ;

    pizzaTruck.driveTo(beach);
    pizzaTruck.cook(pizzaWithExtraAnchovies);
    

    Ok, this silly story was to make the point that it is no simulation of multiple inheritance, it is real multiple inheritance with the proviso that you can only inherit the contract, only inherit from empty abstract base classes which are called interfaces.

    (update: with the coming of default methods interfaces now can also provide some behavior to be inherited)

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

Sidebar

Related Questions

I'm just starting to learn to use HashMap and reading the java tutorial, but
I am just reading through collection java tutorial and wondering why the <E> is
I am reading the Java Hashmap documentation but I don't understand this sentence. Note
I've been reading the Java docs ( http://docs.oracle.com/javase/tutorial/essential/regex/matcher.html ) but am having trouble achieving
I'm currently reading a java concurrency tutorial in http://tutorials.jenkov.com/java-concurrency/creating-and-starting-threads.html I could not understand what
I have been reading through the Java tutorial on RMI. I like the approach
I'm reading this section of Java EE tutorial. http://download.oracle.com/javaee/6/tutorial/doc/bncfu.html#bncfy And have a question: If
I just started reading the Java EE 6 Tutorial , and I'm a little
Reading Java Concurrency In Practice, there's this part in section 3.5: public Holder holder;
I am reading Java Virtual Machine Specification second edition for Java 6. But I

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.