Types of Interfaces in Java: Normal, Functional, Marker, Sealed and Nested (with Examples)
Every type of interface in Java explained with code you can compile: normal, functional, marker, sealed and nested interfaces, the properties every interface has, and the interview questions that follow.
New8 min read

Interviewers love interfaces because one question tells them a lot: do you know the language rules, the Java 8 to 17 additions, and the design reasons behind them? This guide covers every type of interface in Java with examples you can compile, the properties every interface has, and the follow-up questions you are likely to get.
Types of interfaces in Java at a glance
- Normal (regular) interface – a contract with one or more abstract methods, optionally with default, static and private methods.
- Functional interface – exactly one abstract method, so it can be implemented with a lambda or a method reference (
Runnable,Comparator,Function). - Marker interface – no methods at all; it tags a class with a capability (
Serializable,Cloneable,RandomAccess). - Sealed interface (Java 17) – names exactly which classes may implement it.
- Nested interface – declared inside a class or another interface (
Map.Entry).
Generic interfaces such as Comparable<T> are not a separate kind: any of the five above can take type parameters.

Properties of an interface in Java
Before the types, the rules every interface follows. These turn up as quick "true or false" questions in the first round.
- Fields are constants. Every field is implicitly
public static final, so it must be given a value where it is declared. - Abstract methods are public. A method without a body is implicitly
public abstract, and an implementing class cannot make it less visible. - Default and static methods (Java 8) have a body. Default methods are inherited and can be overridden; static methods belong to the interface and are called as
Shape.unitSquare(), never through an object. - Private methods (Java 9) let default and static methods share helper code without exposing it.
- No constructors and no instance state. You cannot write
new Shape(); an anonymous class or a lambda creates an implementation, not the interface itself. - Multiple inheritance of type. A class can implement many interfaces, and an interface can
extendsseveral others.
public interface Shape {
double UNIT = 1.0; // implicitly public static final
double area(); // implicitly public abstract
default String describe() { // Java 8: inherited, can be overridden
return "Shape with area " + format(area());
}
static Shape unitSquare() { // Java 8: called as Shape.unitSquare()
return () -> UNIT * UNIT; // one abstract method, so a lambda works
}
private String format(double value) { // Java 9: helper for default methods
return String.format("%.2f", value);
}
}Interface fields: the trap interviewers set
Because fields are final, this does not compile:
interface Config {
int TIMEOUT_SECONDS = 30;
}
Config.TIMEOUT_SECONDS = 60; // error: cannot assign a value to final variable TIMEOUT_SECONDSAnd do not implement an interface just to borrow its constants (the "constant interface" anti-pattern): the constants leak into the class's public API forever. Put shared constants in a final class with a private constructor, or in an enum.
1. Normal interface
The everyday kind: a contract that several classes fulfil in their own way. Code that depends on the interface rather than a concrete class can swap implementations, and tests can pass a fake.
public interface PaymentGateway {
Receipt charge(String orderId, long amountPaise);
default boolean supports(String currency) {
return "INR".equals(currency);
}
}
public class UpiGateway implements PaymentGateway {
@Override
public Receipt charge(String orderId, long amountPaise) {
// call the payment provider's API here
return new Receipt(orderId, amountPaise, "UPI");
}
}
public record Receipt(String orderId, long amountPaise, String method) {}A checkout service that takes a PaymentGateway never needs to know which provider is behind it. That is the whole point of programming to an interface.
2. Functional interface
A functional interface has exactly one abstract method (a "single abstract method", or SAM, type). That is what lets a lambda or a method reference stand in for an implementation. The @FunctionalInterface annotation is optional, but add it: the compiler then refuses a second abstract method.
Two details interviewers check: default and static methods do not count towards the one, and neither does an abstract method that matches a public method of Object (which is why Comparator, with its equals, is still functional).
@FunctionalInterface
public interface DiscountRule {
long apply(long pricePaise);
default DiscountRule then(DiscountRule next) {
return price -> next.apply(apply(price));
}
}
DiscountRule tenPercentOff = price -> price * 90 / 100;
DiscountRule flat50Off = price -> Math.max(0, price - 5_000);
long finalPrice = tenPercentOff.then(flat50Off).apply(49_900); // 39_910 paise = ₹399.10The JDK ships the common shapes in java.util.function, so you rarely need your own:
Predicate<T>–boolean test(T t), for filters.Function<T, R>–R apply(T t), for transformations.Consumer<T>–void accept(T t), for side effects.Supplier<T>–T get(), for lazy values and factories.UnaryOperator<T>andBiFunction<T, U, R>, plus older ones such asRunnableandCallable.
3. Marker interface
A marker interface has no methods. Implementing it tags a class with a capability, and code checks the tag with instanceof. The JDK's classic markers:
Serializable–ObjectOutputStreamthrowsNotSerializableExceptionfor objects that are not.Cloneable–Object.clone()throwsCloneNotSupportedExceptionunless the class is marked.RandomAccess– tells algorithms such asCollections.binarySearchthat index access is fast, so they use it instead of an iterator.
public interface Auditable {} // the marker
public class Invoice implements Auditable {
// fields and methods
}
void save(Object entity) {
repository.save(entity);
if (entity instanceof Auditable) {
auditLog.record(entity); // only tagged entities are audited
}
}Marker interface or annotation? An interface is a type, so the compiler can enforce it (void archive(Auditable item) only accepts tagged objects). An annotation can carry values and can go on methods and fields, but it is checked by reflection at run time. New code usually reaches for annotations unless that compile-time type check matters.
Functional interface vs marker interface
- Methods: a functional interface has exactly one abstract method; a marker interface has none.
- Purpose: functional interfaces pass behaviour around as a value; marker interfaces attach a capability or metadata to a class.
- How it is used: functional interfaces with lambdas and method references; marker interfaces with
instanceofchecks inside libraries and frameworks. - Examples:
Runnable,Comparator,PredicateversusSerializable,Cloneable,RandomAccess. - Annotation: functional interfaces can carry
@FunctionalInterface; markers have no equivalent.
4. Sealed interface (Java 17)
A sealed interface lists exactly which types may implement it with permits. Each permitted type must be final, sealed or non-sealed (records are implicitly final). Because the compiler knows every case, a switch over a sealed type needs no default branch, and adding a new case breaks the build exactly where it should.
public sealed interface PaymentStatus permits Paid, Pending, Failed {}
public record Paid(String transactionId) implements PaymentStatus {}
public record Pending() implements PaymentStatus {}
public record Failed(String reason) implements PaymentStatus {}
static String message(PaymentStatus status) {
return switch (status) { // Java 21: exhaustive, no default needed
case Paid paid -> "Paid: " + paid.transactionId();
case Pending pending -> "Waiting for the bank";
case Failed failed -> "Failed: " + failed.reason();
};
}The permitted types must live in the same module (or the same package, if you are not using modules).
5. Nested interface
An interface declared inside a class or another interface. It is implicitly static, so it needs no outer instance. Use it when the interface only makes sense next to its outer type, the way Map.Entry<K, V> only makes sense with Map.
public class Checkout {
public interface Listener {
void onPaid(String orderId);
}
private final List<Listener> listeners = new ArrayList<>();
public void addListener(Listener listener) {
listeners.add(listener);
}
}
checkout.addListener(orderId -> emailService.sendReceipt(orderId));Interface vs abstract class
The question that follows any interface discussion:
- State: an interface has only constants; an abstract class can have instance fields.
- Constructors: an abstract class can have them; an interface cannot.
- Inheritance: a class implements many interfaces but extends only one class.
- Visibility: interface methods are public (or private helpers); an abstract class can use
protectedand package-private members. - When to use which: an interface for a capability many unrelated classes share; an abstract class for a family of closely related classes that share code and state.
Java interface interview questions
Can an interface have a constructor?
No. An interface has no instance state to initialise, so there is nothing for a constructor to do.
Can an interface have private methods?
Yes, since Java 9. They exist so default and static methods can share code without making it part of the public contract.
What happens if a class implements two interfaces with the same default method?
It does not compile until the class overrides the method. Inside the override it can pick one: Swimmer.super.move().
class Duck implements Swimmer, Flyer {
@Override
public String move() {
return Swimmer.super.move();
}
}Comparator declares two abstract methods. How is it a functional interface?
Its second abstract method is equals(Object), which matches a public method of Object and so does not count. Only compare does.
Can an interface extend a class?
No. An interface can only extend other interfaces, and it can extend several of them.
Can a functional interface have default methods?
Yes, as many as you like. Only abstract methods are counted.
Are marker interfaces still used?
Yes, inside the JDK and libraries (Serializable above all). For new code, an annotation is usually the better fit unless you want the compile-time type check.
Practise the rest of core Java
Interfaces are one chapter of the core-Java round. If you are preparing for interviews, these go deeper:
- Java Learning Resources: Interview Preparation – OOP, interfaces, exceptions, collections, Java 8 and more, from beginner to advanced.
- Complete Collections Framework Q&A – the questions that usually come straight after this topic.
- Supercharge Your Java Skills: 12+ eBook bundle – a wider library for revision.
Planning your preparation? Follow the 30-day Java interview roadmap, and drill thousands more questions with answers on prepare-java.techtriber.com.




