← 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?
- A.Liskov Substitution
- B.Open/Closed
- C.Interface Segregation
- 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 →