Because
Java does not allow executable statements in the class body - it's just the way the language is designed. It allows declarations, and you can initialise a variable when you declare it (as you have on lines 5-7), but not other statements.
You can move them to an initialisation block (put the statements in {...}), but it will be clearer if you just put the initialisation code in a constructor.