class Type {
int s=10;
s = 10;
public static void main(String[]args)
{
System.out.println(s);
}
}
this program creat
In Java, the only things that are allowed directly within class bodies are methods, field declarations and blocks, no expression or non-declarative statements. These can only be added within blocks.
class Type {
int s;
{ s = 10; }
}
Putting it in a constructor is probably a better idea though.
class Type {
int s;
public Type() {
s = 10;
}
}