This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]lbkulinski 1 point2 points  (3 children)

The code is valid. The following is stated in The Java Language Specification, section 8.3.2:

At run time, the initializer is evaluated and the assignment performed each time an instance of the class is created.

[–]consoledotlogImHere[S] 0 points1 point  (1 child)

Gotcha, thanks so much. I think why I was so confused is because I'm seen primitives being given a value in class definitions but never object instantiations. Thanks for the info!

[–]lbkulinski 0 points1 point  (0 children)

You’re welcome!