Given:
2. public class Main { 3. static int x; 4. int y; 5. public static int getX() { return x; } 6. public static void setX(int newX) { x = newX; } 7. public int getY() { return y; } 8. public void setY(int newY) { y = newY; } 9. }
Which lines of code need to be changed to make the class thread safe? (Choose all that apply.)
H:Note
B-G are correct.
The variables need to be private, and even methods that don't change a variable's value need to be synchronized if they access the variable.
A is incorrect.
This class statement has no effect on thread safety-ness.