java - Why is it illegal to assign a class variable that was just declared? -


class {     public int somevar;     somevar = 123;      /* cannot find symbol */ } 

why cant language see variable declared? , unique java or true in classful oop languages?

in java, can declare instance variables inside class outside method, statements such somevar = 123; must within method (or constructor, static initializer, or instance initializer).


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -