Quick revision
The short answer
Changing an abstract class to an interface breaks binary compatibility: clients must change extends to implements and recompile, because the JVM links calls to class methods and interface methods with different instructions, and constructor calls, protected members and fields disappear. So we migrate in steps: introduce the interface and have the abstract class implement it, add API methods that accept the interface alongside the old ones, deprecate direct extension with a timeline while tracking usage by scanning the 60 services, provide automated refactoring such as OpenRewrite recipes, and make the final break only in a major version with clear release notes.
What to remember
In this answer, we saw that turning an abstract class into an interface breaks binary and source compatibility, because extends must become implements, class method calls become interface calls, and constructors, protected members and fields disappear. We migrated in compatible steps: introduce the interface and have the class implement it, add API overloads that accept the interface, deprecate the old paths with forRemoval and a timeline, track usage by scanning the 60 services, offer OpenRewrite recipes, and make the final break in a major version with clear release notes.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Changing an abstract class to an interface breaks binary compatibility: clients must change extends to implements and recompile, because the JVM links calls to class methods and interface methods with different instructions, and constructor calls, protected members and fields disappear. So we migrate in steps: introduce the interface and have the abstract class implement it, add API methods that accept the interface alongside the old ones, deprecate direct extension with a timeline while tracking usage by scanning the 60 services, provide automated refactoring such as OpenRewrite recipes, and make the final break only in a major version with clear release notes.
Why this question is asked
An internal SDK used by 60 services is effectively a public API: nobody can change it in a single commit, and each team has its own release schedule. Moving from abstract classes to interfaces is a good change, because it frees clients from using up their single superclass and makes the SDK easier to evolve, but doing it carelessly can break builds or, worse, cause linkage errors in production. Interviewers ask this at senior level to see whether we understand binary compatibility and can plan a migration that teams can absorb. In this answer, we will see exactly what breaks, then walk through a staged release plan, how to track and help clients, and how to finish the migration.
1A Quick Recap of Binary and Source Compatibility
Source compatibility means client code still compiles against the new version. Binary compatibility means client code that was compiled against the old version still links and runs against the new one without recompiling. In a company with 60 services, binary compatibility matters a lot, because a service may pick up a new SDK version transitively through another library without being rebuilt against it.
The Java Language Specification lists which changes keep binary compatibility. Changing a class into an interface is explicitly not one of them.
2What Breaks When a Class Becomes an Interface
Here is the client code as it exists today, and what happens if version 5.0 simply turns the abstract class into an interface.
| Client code | Without recompiling | After recompiling |
|---|---|---|
class X extends MessageHandler | IncompatibleClassChangeError on load | Compile error: must use implements |
handler.handle(msg) | IncompatibleClassChangeError at the call | Compiles as invokeinterface |
super(metrics) | Fails with the class | Compile error: no constructor |
| uses protected field metrics | Fails with the class | Compile error: no such field |
At the bytecode level, calls such as handler.handle(msg) were compiled as invokevirtual on a class. Against an interface, the JVM expects invokeinterface, and an old call site fails with IncompatibleClassChangeError. On the source side, every client must change extends to implements, remove the super(...) call, and find a new home for the shared field and the onError behaviour, since interfaces have no instance state and no protected members. So the change is both binary and source incompatible, and it touches every implementer.
3Introduce the Interface Without Breaking Anyone
The first release adds the interface and makes the existing abstract class implement it. Nothing a client compiled against is removed, so this release is compatible in both senses and can ship as a minor version, say 4.3.
The shared state does not move into the interface; it cannot. Instead we decide where it really belongs. Often metrics should be injected into the handler by the client or provided by the SDK's dispatcher, which simplifies the interface. The abstract class can stay as an optional helper, a skeletal implementation, for clients who like it.
4Accept the Interface in the APIs
Next, SDK methods that take a MessageHandler should accept a Handler. There is a trap here: changing a parameter type from MessageHandler to Handler changes the method's descriptor, so it is itself a binary incompatible change. The safe way is to add an overload that takes the interface and keep the old method as a delegate.
Old clients still link to register(MessageHandler); recompiled clients pick the most specific overload, which is still the old one for a MessageHandler argument, so the deprecation warning tells them to move. New code written against the interface uses register(Handler) directly.
5Deprecate, Track and Help
With the interface in place, we deprecate direct extension of MessageHandler with a clear timeline, for example removal in 5.0 six months later. Deprecation alone does not tell us who is affected, so we scan. A small CI job can pull the built artifacts of all 60 services and list classes whose superclass is MessageHandler and calls to the deprecated register method, using bytecode analysis such as jdeps output or an ArchUnit scan. Publishing that list per team each week turns a vague request into a visible, shrinking number.
To lower the cost for clients, we provide automated refactoring, for example custom OpenRewrite recipes that change extends MessageHandler to implements Handler, remove the super call and switch register calls. Teams that run the recipe get a reviewed pull request instead of an afternoon of manual edits. For the few unusual cases, we offer office hours or pair with the team.
- 4.3: add Handler; MessageHandler implements itCompatible, minor release
- 4.4: register(Handler) added, old one deprecatedCompatible,
forRemovalwarnings - Scan 60 services weekly; ship recipesUsage list per team
- Remaining users near zero?Yes5.0: remove old methods; keep or drop helper classNoHelp remaining teams; keep 4.x patched
4 steps in order. Play them, or step through them one at a time.
6The Major Version and Its Release Notes
We follow semantic versioning: everything up to now was a minor release because it was compatible, and the final removal of the deprecated methods, or a change to MessageHandler itself, goes into a major version, 5.0. The release notes list each breaking change, the replacement, the recipe that automates it and the error a client will see if they upgrade without migrating, so the failure is recognisable.
We also keep the last 4.x line patched for security fixes for an agreed period, so that a team with a hard deadline elsewhere is not forced to migrate in an emergency. And because transitive dependencies can bring 5.0 into a service that has not migrated, a dependency convergence rule or a Maven enforcer check in the shared build configuration helps catch mixed versions at build time instead of at run time.
7Follow-up questions
Could we add default methods to the abstract class's replacement interface later without breaking clients?
Adding a default method is binary compatible, so old clients keep working. It is not risk-free, though: if a client class already has a method with the same signature, the client's method silently overrides the new default, possibly with different meaning. We treat any new default on a widely implemented interface as an API change that needs review.
Why not keep the abstract classes forever?
We can keep the abstract class as an optional helper. What we want to remove is the requirement to extend it, because it uses up the client's single superclass and freezes the SDK's internal state into every client. Once all APIs accept the interface, the helper can stay or go based on whether teams find it useful.
How long should the deprecation period be?
Long enough for every team to fit the change into a normal planning cycle, often one or two quarters for an internal SDK. The usage data decides more than the calendar: if 55 services have migrated in two months, we chase the last five rather than waiting, and if many are stuck, we extend.
8Conclusion
In this answer, we saw that turning an abstract class into an interface breaks binary and source compatibility, because extends must become implements, class method calls become interface calls, and constructors, protected members and fields disappear. We migrated in compatible steps: introduce the interface and have the class implement it, add API overloads that accept the interface, deprecate the old paths with forRemoval and a timeline, track usage by scanning the 60 services, offer OpenRewrite recipes, and make the final break in a major version with clear release notes.
Open with
First, I'd be clear that changing an abstract class into an interface is binary incompatible. Clients compiled against the class would fail with IncompatibleClassChangeError, because their class now has an interface as its superclass and calls compiled as invokevirtual expect a class, and after recompiling they'd still have to change extends to implements, drop the super constructor call, and lose protected fields.
Then, if they want more
With 60 services on their own release schedules, we can't do that in one step. So the plan is staged. In a minor release, add the new interface and make the existing abstract class implement it; nothing breaks.
Then add API overloads that accept the interface and keep the old methods as deprecated delegates, because changing a parameter type is itself a binary break. Mark extension of the abstract class and the old methods as deprecated for removal with a date.
To know who's affected, I'd run a weekly scan of all services' artifacts for subclasses and old calls, and publish the remaining count per team. To cut their cost, I'd ship OpenRewrite recipes that do the edit, plus office hours for the odd cases.
Finally, under semantic versioning, the removal goes into a major release with release notes listing each break, its replacement and the error you'd see, while the last minor line keeps getting security patches for a while.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "An internal SDK used by 60 services exposes abstract classes for clients to extend. You...": https://scrivio-interview-library.netlify.app/java/interfaces-and-abstract-classes/e128efeecf/