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

The Archive Base Latest Questions

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

Trying to understand a question I got wrong on a test: How does inheritance

  • 0

Trying to understand a question I got wrong on a test:


How does inheritance differ from implementing interfaces?

  1. With inheritance, a class gains behavior from its superclass.
  2. With interfaces, a class gains behavior from the interface it implements. (this is the one I chose)
  3. With inheritance, a class must implement the methods defined by its superclass.
  4. With interfaces, a class gains both instance variables and behaviors from the interface it implements.

The way I was thinking is that interfaces define behavior, while superclasses define characteristics… or are they the same? Or am I completely backwards in my understanding?


Edit: I guess I should specify that I do know the difference between interfaces and inheritance. I’m just wondering about the two options which use the term behavior. I don’t know if the prof was nitpicking about terminology, or if he asked the question poorly.

I know that when you implement an interface, you have to implement all the methods as defined in the interface. As such, I would say that the interface defines the behavior that a class must have, but extending another superclass (although it does also define some behaviors (more can be given to the subclass), it doesn’t seem to fit as strongly as the interface defining behaviors. If the class implements an interface, you can be sure that it has certain behaviors.

Maybe the question was meant to ask whether or not the interface itself has the code for the behavior, or if it’s just the definition – which if worded that way, I would have known the answer.

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

    I think some of your misunderstanding might stem purely from semantics. Perhaps a more straightforward way of describing an interface is that it defines an API but does not provide an implementation of that API. One caveat is that I will use Java for my example but in a language like C++, implementing an interface is inheritance of a special sort – namely inheriting from a class consisting of pure virtual functions.

    In Java, for instance, you might have an EventListener interface defined as:

    public interface IEventListener {
        public void handleEvent(Event event);
    }
    

    The interface does not, to use the question’s verbiage, say anything about how a class that implements the IEventListener interface will behave when it receives an event it only ensures that any class implementing this interface will have the characteristic of being able to receive an event of type Event.

    Inheritance, on the other hand, allows super classes to also inherit behavior (implementation). For instance, consider the following Java base class:

    public abstract BaseClass {
        public void baseMethod(int value) {
            System.out.println(int);
    }
    
    public class SubClass extends BaseClass {
    }
    

    Any class that inherits from BaseClass gains both the API (characteristics) of BaseClass and also the implementation (behavior). In other words not only can you invoke instanceOfSubClass.baseMethod(1), a characteristic, doing so will result in the behavior defined in the BaseClass, namely 1 being printed to the console.

    So your answer (2) is incorrect because interfaces do not specify behavior (implementation) only API (characteristics). Inheritance can handle both.

    I think the point of the question is to explain that inheritance is specifically useful when you want to share behavior and not just API. That said, implementation (behavior) can also be shared via composition and such a strategy is often better – see Item 16 in Bloch’s Effective Java for an excellent discussion.

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

Sidebar

Related Questions

I'm trying to understand what exactly the above (in my question's Title) means? This
I'm sorry to ask this question but I have spent hours trying to understand
This might be a naive question. However, I am just trying to understand why
My question is a bit tricky, I am trying best to make you understand
Trying to understand what's the correct way of implementing OpenID authentication with Spring Security.
Trying to understand PNG format. Consider this PNG Image: The Image is taken from
I'm trying to understand the new arel engine in Rails 3 and I've got
Asked the same question here but got no answer, so I'm trying here instead
I am trying to test some code. The main script requires imports from a
I'm trying to understand Viola Jones method, and I've mostly got it. It uses

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.