What is the Single Responsibility Principle (SRP) in Java, and can you give an example?
The SRP means that a class should be responsible for only one task, but you can have multiple tasks within a class as long as they are related.
That's partially correct. The principle actually advocates that a class should have one reason to change, and tasks should be highly cohesive, not just related.
Can you give an example of a class that violates SRP and how you would refactor it?