Working with Methods Flashcards
1
Q
Does the code compile with an uninitialised final instance or static variable?
A
1. If you declare a field to be final, it must be explicitly initialized by the time the creation of an object of the class is complete. So you can either initialize it immediately: private final double ANGLE = 0; IMPORTANT or you can initialize it in the constructor or an instance block.
- Trying to change a final variable will make the code fail to compile as well, you can’t change its value once it is set.
2
Q
Can the synchronized keyword be applied to a class?
A
the synchronized keyword can never be applied to a class.