Which of the following will compile when inserted in the following code?
Choose all that apply
public class MyClass3 { final String value1 = "1"; static String value2 = "2"; String value3 = "3"; { /*ww w. j a v a2 s . c o m*/ // CODE SNIPPET 1 } static { // CODE SNIPPET 2 } }
B, C, E.
value1 is a final instance variable.
It can only be set once: in the variable declaration, an instance initializer, or a constructor.
Option A does not compile because the final variable was already set in the declaration.
value2 is a static variable.
Both instance and static initializers are able to access static variables, making options B and E correct.
value3 is an instance variable.
Options D and F do not compile because a static initializer does not have access to instance variables.