Interview Q&A / Object-Oriented Programming

BeginnerQuick answer1 min readUpdated 3 Oct 2026

Explain the Interface Segregation Principle with a Worker interface example.

SHORT ANSWER

No class should be forced to implement methods it does not use. Split one big interface into small, focused ones so each class picks only what applies.

Explain it simply

A restaurant menu card for a tea stall should not list biryani, sushi and pizza. A customer who wants chai has to read through items the stall cannot serve. A big interface does the same to classes: they must write empty or failing methods for things they never do.

Example

java
// Fat interface
interface Worker {
    void work();
    void eat();
    void sleep();
}
class Robot implements Worker {
    public void work() { }
    public void eat()  { throw new UnsupportedOperationException(); }   // forced
    public void sleep() { throw new UnsupportedOperationException(); }  // forced
}

// Segregated
interface Workable { void work(); }
interface Eatable  { void eat(); }

class Human implements Workable, Eatable {
    public void work() { }
    public void eat()  { }
}
class Robot2 implements Workable {
    public void work() { }
}

Code that only needs workers asks for Workable and works with both humans and robots.

What to say in the interview

"ISP says clients should not depend on methods they do not use. I break large interfaces into small role-based ones, so implementers provide only relevant behaviour and callers depend on the narrowest interface they need."

Common mistakes

  • Making one interface per method regardless of how they are used together.

#solid#isp#java

Related questions

Practise more Object-Oriented Programming questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Object-Oriented Programming quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.