Skills101
← All practice quizzes

Quiz: SOLID in Java

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

Take one messy Java class from a college results system and fix it with the five SOLID principles, with a runnable Java program for every step.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    In the original ResultService.publish(), how many different reasons to change did the class have?

  2. Question 2

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

  3. Question 3

    What does this print?

    interface Shape { double area(); }
    
    class Rect implements Shape {
        int w, h;
        Rect(int w, int h) { this.w = w; this.h = h; }
        public double area() { return w * h; }
    }
    
    class Circle implements Shape {
        int r;
        Circle(int r) { this.r = r; }
        public double area() { return 3 * r * r; }
    }
    
    public class Main {
        public static void main(String[] args) {
            Shape[] shapes = { new Rect(2, 5), new Circle(2) };
            double total = 0;
            for (Shape s : shapes) total += s.area();
            System.out.println(total);
        }
    }
    
  4. Question 4

    A subclass overrides a method and throws UnsupportedOperationException. Which principle is most likely broken?

  5. Question 5

    Why is ResultService(ResultStore store, Notifier notifier) easier to test than a class that does new MySqlStore() inside?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →