0
Well, the substitute for getters and setters would be declaring fields with public access modifier. It's not the best practice through. toString method has nothing to do with mutators. It should just represent object as a String without changing the state. So, no, you can't use mutators inside toString method, it's a bad practice. You can call getters inside toString method, but it is pointless since toString is declared inside a class hence having a full access to private fields.
8th Sep 2020, 9:21 AM
Aleksandrs
Aleksandrs - avatar