public class class2 {
static int number3 = 86;
public static void Whale() {
static int number4 = 86;
}
}
why is it i get an error on line number 5 and not line number 2? Thanks!
Because Whale is a method, and you can't define a static field within a method. You can have a local number4 like
public static void Whale() {
int number4 = 86;
or a static field like
static int number4 = 86;
public static void Whale() {
finally, by convention class names should start with a capital letter (CamelCase) and method names with a lower case letter (camelCase).
You need to understand that java doesn't support static local variables unlike C/C++. But in some cases Closures may help you for your goal.
Try these some sources for Closures -