🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: SOLID in Java: all 10 questions

Quiz: SOLID in Java · Question 2 of 10

A PaymentProcessor has if (type.equals("UPI")) … else if (type.equals("CARD")) …. Adding NetBanking needs another else…

A PaymentProcessor has if (type.equals("UPI")) … else if (type.equals("CARD")) …. Adding NetBanking needs another else if. Which principle is being broken?

  1. A.Liskov Substitution
  2. B.Open/Closed
  3. C.Interface Segregation
  4. D.Single Responsibility only
Answer & explanation

Correct answer: Open/Closed

A new payment type should be a new class implementing an interface, so the existing code is not edited.

Can you get the rest right without peeking?

Take the timed Quiz: SOLID in Java quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →