Can you provide a scenario where creating a custom marker interface would be beneficial?

A custom marker interface is useful when you want to identify or categorize specific classes for special processing without forcing them to implement any methods. It acts as a metadata tag that allows frameworks or application logic to recognize eligible classes and apply certain rules, validations, or behaviors at runtime.

Key Points

Example

Suppose a banking application allows only approved objects to be transferred between internal systems. A custom marker interface called Transferable can be implemented by authorized classes. Before processing a transfer, the system checks whether the object implements Transferable and rejects unauthorized objects.

// Marker Interface
interface Transferable {
}

// Eligible Class
class CustomerAccount implements Transferable {
    private String accountNumber;

    public CustomerAccount(String accountNumber) {
        this.accountNumber = accountNumber;
    }
}

// Non-Eligible Class
class AuditLog {
}

public class MarkerInterfaceDemo {

    public static void processTransfer(Object obj) {
        if (obj instanceof Transferable) {
            System.out.println("Transfer allowed.");
        } else {
            System.out.println("Transfer denied.");
        }
    }

    public static void main(String[] args) {
        processTransfer(new CustomerAccount("ACC123"));
        processTransfer(new AuditLog());
    }
}

Interview Tip

A concise interview answer is: "A custom marker interface is beneficial when certain classes need special handling without adding behavior. For example, a Transferable marker interface can identify which objects are allowed for data transfer, enabling the application to apply security or processing rules at runtime."

Last updated: 16 July 2026

Previous question: What is a marker interface in Java?

Next question: How does Java determine which method to call in the case of method overloading?

More Core Java - Level III interview questions

All Core Java - Level III questions