Quick revision
The short answer
Adding an abstract method to a published interface is binary compatible, so old implementer class files still load, but calling the new method on them throws AbstractMethodError, and they stop compiling when rebuilt. Adding a default method is binary compatible and usually source compatible, unless it clashes with a method an implementer already has or with another default. Adding a static method is both binary and source compatible, while removing a method or changing its signature breaks both.
What to remember
In this answer, we saw that binary compatibility means old class files still link, and source compatibility means old code still compiles. Adding an abstract method keeps the first but breaks the second and fails at run time with AbstractMethodError when called. A default method keeps both except when it clashes with existing methods or other defaults. A static method keeps both. Removing or changing a signature, including a return type, breaks both, and japicmp or Revapi can enforce these rules in CI.
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.
Adding an abstract method to a published interface is binary compatible, so old implementer class files still load, but calling the new method on them throws AbstractMethodError, and they stop compiling when rebuilt. Adding a default method is binary compatible and usually source compatible, unless it clashes with a method an implementer already has or with another default. Adding a static method is both binary and source compatible, while removing a method or changing its signature breaks both.
Why this question is asked
Anyone who publishes a library, even one used only inside a company, eventually needs to change an interface that other code implements or calls. The words binary compatible and source compatible describe two different promises, and mixing them up is how a harmless-looking release turns into AbstractMethodError in production. Interviewers ask this to see whether we can reason about what the JVM checks when classes link, not only what javac checks. In this answer, we will define the two kinds of compatibility, walk through adding an abstract method, a default method and a static method, look at removals and signature changes, and see how tools such as japicmp and Revapi check all this in CI.
1A Quick Recap: Two Kinds of Compatibility
A change is source compatible if code that compiled against the old version still compiles, unchanged, against the new one. A change is binary compatible if class files that were compiled against the old version still link and run against the new one without being recompiled. The Java Language Specification has a whole chapter, chapter 13, on what counts as binary compatible.
The difference matters because in real systems the two happen at different times. A library is upgraded in a service's build, but that service also has twenty other jars on its classpath that were compiled years ago against the older library and will never be rebuilt. Those old jars depend on binary compatibility; our own code depends on source compatibility.
2Adding an Abstract Method
Suppose version 1 of a library has interface Shape with one method, and a plug-in jar, compiled against version 1, implements it. Version 2 adds a second abstract method.
Notice the two different failures. The JVM does not check, when it loads Square, that every interface method is implemented, so the old class file loads happily. That is why the JLS calls this change binary compatible. The failure only appears when someone actually calls the missing method, which may be weeks later and only on a rare code path. The source failure, on the other hand, is immediate: the plug-in cannot be rebuilt until it implements perimeter().
3Adding a Default Method
If version 2 adds perimeter() as a default method instead, old class files get the default body when the method is called, and old sources still compile. This is the change Java 8 used to add stream() and removeIf() to Collection. It is not risk-free, though, and the risks are about clashes.
Both clashes are source incompatibilities. The second one is also visible at run time for old binaries: the JLS notes that adding a default method may cause an IncompatibleClassChangeError if a pre-existing binary invokes a method that now has two conflicting defaults. There is a third, quieter risk. If an implementer already had a describe() method with the same signature, it now silently overrides our default, and if it meant something different, callers that expect our meaning get its behaviour instead. So a default method is safe in most cases, but its name should be chosen to avoid likely collisions.
4Adding a Static Method
Static methods on interfaces are the easy case. They are not inherited by implementing classes, so they cannot clash with anything an implementer has, and calls are always written with the interface name, as in Shape.unitSquare().
So adding a static method is both binary and source compatible. It is a good home for factory and helper methods when we want to grow an interface without touching its implementers.
5Removing or Changing a Method
Removing a method, or changing anything in its signature, breaks both kinds of compatibility. Callers compiled against the old version fail with NoSuchMethodError when they reach the call, and their sources stop compiling. Implementers lose their override relationship and fail in their own ways.
Notice that the method descriptor in a class file includes the return type. So even changing a return type from Collection to List, which looks harmless in source and still compiles for callers, breaks old binaries, because the JVM looks for the exact descriptor that was compiled. The same applies to changing a parameter from int to long.
| Change | Old binaries | Old sources |
|---|---|---|
| Add abstract method | Load fine; AbstractMethodError if called | Implementers fail to compile |
| Add default method | Fine; ICCE if two defaults now conflict | Fine unless it clashes |
| Add static method | Fine | Fine |
| Remove a method | NoSuchMethodError at the call | Callers fail to compile |
| Change return or parameter type | NoSuchMethodError at the call | Usually fails to compile |
6Checking Compatibility in CI
We should not rely on reviewers to spot these cases. japicmp and Revapi compare the compiled API of a new library version with the last released one and report every binary and source incompatible change. Both have Maven and Gradle integrations, so the check runs on every build.
The useful policy is to tie the check to semantic versioning: if the version is a minor or patch release, any incompatible change fails the build; if it is a major release, the report becomes the migration notes. That turns compatibility from a matter of memory into a gate.
7Follow-up questions
Why does the JVM not check for missing interface methods when it loads a class?
Because linking is lazy and the JVM's job at load time is only to make sure the class file is well formed and its declared relationships exist. Method resolution happens when a call site is first executed. That design lets old binaries keep working when interfaces grow, which is exactly what binary compatibility needs, at the cost of late AbstractMethodError failures.
Is turning an abstract method into a default method compatible?
Yes. Old implementers already have the method, so they keep overriding it, and new implementers may skip it. It is binary and source compatible, apart from the same rare conflict with another interface's default.
What do japicmp and Revapi not catch?
Behavioural changes. If a method keeps its signature but starts throwing a new runtime exception, returning null, or interpreting an argument differently, the tools see no difference. Those need tests, release notes and, for shared libraries, contract tests owned by the consumers.
8Conclusion
In this answer, we saw that binary compatibility means old class files still link, and source compatibility means old code still compiles. Adding an abstract method keeps the first but breaks the second and fails at run time with AbstractMethodError when called. A default method keeps both except when it clashes with existing methods or other defaults. A static method keeps both. Removing or changing a signature, including a return type, breaks both, and japicmp or Revapi can enforce these rules in CI.
Open with
I would separate the two promises first. Source compatible means code that compiled before still compiles; binary compatible means class files compiled before still link and run without recompiling.
Then, if they want more
Adding an abstract method is binary compatible in the JLS sense: an old implementer still loads, but if anyone calls the new method on it, the JVM throws AbstractMethodError, and when that implementer is rebuilt it fails to compile because it does not implement the method.
Adding a default method is binary compatible and usually source compatible, which is how Java 8 grew Collection. It breaks only on clashes: an implementer with a same-named method but a different return type, or one that also inherits a conflicting default from another interface, which can even show up at run time as IncompatibleClassChangeError.
Adding a static method is safe both ways because static interface methods are not inherited. Removing a method or changing its signature breaks both, including just changing the return type, since the descriptor includes it. In practice I would put japicmp or Revapi in CI and fail any minor release that contains an incompatible change.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 8
- 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 "Which changes to a published interface are binary compatible and which are source...": https://scrivio-interview-library.netlify.app/java/interfaces-and-abstract-classes/6b29ce2469/