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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:40:52+00:00 2026-05-19T03:40:52+00:00

In Java people often define an interface together with a class and use interface

  • 0

In Java people often define an interface together with a class and use interface name instead of class name where possible, in order to allow new implementations later. Here the logical interface is duplicated.

This kind of “just in case” duplication would not be necessary if Java allowed using a class as an interface eg: class MyScanner extends MyStuff implements java.util.Scanner. Also this would ease the situation where I need to provide a class-type but I don’t want to extend that class.

As I understand, “implementing a class” would be rejected not only by the compiler but also by the JVM (if I hacked this declaration into classfile). Are there some technical difficulties for this or it’s not regarded as important thing? It doesn’t look like a backward-compatiblity problem (I mean, old code would run fine if JVM supported this).

EDIT: for clarification, I will copy here StriplingWarrior’s much better wording of the same questions:

Why can’t a class “implement” another class’s method contract without actually extending that class? Is it a technical issue? Would it somehow open us up to some issues that the OP can’t foresee?

  • 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-19T03:40:52+00:00Added an answer on May 19, 2026 at 3:40 am

    Do I understant correctly that MyClass implements AClass would mean that MyClass must provide (or inherit) implementations for all public methods that AClass has? I.e. each class implicitly defines an interface consisting of its public methods?

    If so, then the problem I see with that is that interfaces are really something very different from classes, and the two should not be mixed like that. Interfaces define a contract, classes an implementation. A consequence of that: The functionality of classes can be extended relatively freely, but not so interfaces with existing implementations.

    So there you have a very concrete reason why your suggestion would be bad: you could never add any public method to any class without risking to break some code that implements that class.

    And on the other hand, what problems would it solve? The code duplication when you have an interface with a single implementation? How about solving that by not doing it? IMO it’s usually something done by people doing TDD dogmatically while using outdated mocking frameworks not capable of mocking concrete classes.

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

Sidebar

Related Questions

When java was young, people were excited about writing applets. They were cool and
I will choose Java as an example, most people know it, though every other
What is the best OS for Java development? People from Sun are pushing the
Whenever a question pops up on SO about Java synchronization, some people are very
(Java question) If I reference a field in an inner class, does this cause
I am asked by one of colleague about the Throwable class in java API.
Hey peoples, I've been studying Java for a couple of weeks, and have decided
Java has generics and C++ provides a very strong programming model with template s.
Java has a convenient split method: String str = The quick brown fox; String[]
Java Newbie here. I have a JFrame that I added to my netbeans project,

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.