In java class you can declare or define (initialize at the same time) variables but not set any values or initialize them later. The second line can only be done in a method body or a constructor.
Example 1:
public class Test
{
String name;
void doStuff(){
name = " ";
}
}
Example 2:
public class Test
{
String name = "set some value";
}
You can read more about it HERE .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.