when I am coding this at class level
int a; a=5;
it throws error : \"identifier expected\"
But when I declare it as a local variable li
You can not write code into the class, only in method, constructor or into initializer {} block. That is why you get syntax error. Probably you want to use initializer block like this:
class my{ int a; { a=1; } }