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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:37:50+00:00 2026-06-07T13:37:50+00:00

If I have a few subtypes, each inheriting an abstract superclass and this superclass

  • 0

If I have a few subtypes, each inheriting an abstract superclass and this superclass implements an interface- when implementing dynamic binding/polymorphism is there any difference between declaring the objects as the superclass type, opposed to the interface type?

So A,B,C,D extend from S and S implements I.

I could do:

S a = new A();
S b = new B();

or

I a = new A();
I b = new B();

I tend to use interfaces, but i’m suddenly wondering if its better to use the superclass in case you were to split the interface into two interfaces….

  • 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-07T13:37:53+00:00Added an answer on June 7, 2026 at 1:37 pm

    From a typing perspective, there is no difference. (Unless you specifically “go looking” by using reflection to introspect the types at runtime …)

    From a runtime performance perspective, there is no difference. (Except from some possible very minor differences in the time to load classes … which can be ignored in all realistic use-cases.)

    From an code implementation perspective, there are advantages and disadvantages in the two approaches:

    If you use just superclasses (no interfaces), you may be able to write less code. But the flip-side is that your code is less flexible:

    • You are trying the external API to the implementation in a way that restricts your ability to write new implementations. The java.io.OutputStream class is a classic example of this. Because it is a class, you have to create a subclass in order to implement a new stream type, and you may find that you have to code the subclass to override all infrastructure that you “inherit”.

    • The fact a class can have just one superclass further restricts you to a tree-shaped API hierarchy.

    • Clients have to be coded against the implementation class APIs to a greater degree … because that is all there is. And that restricts the programmer’s ability to change his / her mind about.


    Bottom line: If the particular use-case does not require you to be able to do these things (now or in the future) then using interfaces has no benefit. But few use-cases are really like that. And the incremental implementation effort of using interfaces is small.


    I should add, I am not asking whether or not to use interfaces. I am guessing interfaces can be used just to force somebody to implement methods (and never declared as a type)?

    Well yea. But so can abstract methods. That’s not the real point of using interfaces. The real point is that interfaces:

    • allow richer type hierarchies that are possible using classes, and
    • allow client code to be written independently of the implementation classes.

    I am just asking what benefits does using the interfaces as the object type bring for polymorphism?

    From the typing and performance levels: none – see above.

    I guess, you could argue that if you use interfaces in a way that crosses the implementation hierarchy, then you have more flexibility at the client level. I guess you could call that a “benefit for polymorphism”. (By contrast, if your interface hierarchy exactly mirrors your implementation class hierarchy, then you’ve probably not achieved anything … at least in terms of the code as written.)

    However, polymorphism is a means to an end, not a goal in its own right, so I would argue that asking about “benefits for polymorphism” in an abstract sense is missing the point. The real point is designing and implementing programs in a way that makes sense, and results in maintainable code.

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

Sidebar

Related Questions

I have few question in this regard When you create an internet page, does
I have few questions connected with struct and typedef, there is piece of code
i have few variables like this: self.lamp_1 self.lamp_2 self.lamp_3 self.lamp_4 and now i want
I have few TabPages and each contains rich text box. How can I access
I have few textviews and it looks like this now: ramdomName 10.20 - 11.30
I have few textblocks, with custom font family which work fine: FontFamily={StaticResource CodeBold} This
I have few questions on this as selenium always need windowid to get control
I have few questions about this code: <?php $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv =
I have few thousand of items. For each item I need to download a
I have few form fields, each input and label is wrapped inside a div

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.