Ist statische Variable in einer anonymen inneren Klasse zulässig? Einige sagen nein, aber ich kann ohne Fehler in der So
Posted: 23 Feb 2025, 08:11
interface Workables {
void Work();
}
public class AnonymousTry {
public static void main(String[] args) {
Workables w = new Workables() {
static int x = 10;
public void Work() {
System.out.println("Working..."+x);
}
};
w.Work();
}
}
< /code>
Ich kann ohne Fehler in Eclipse ausführen. Aber konnte nicht in Online -Compilern. Ich bin verwirrt darüber, ob die anonyme innere Klasse statische Variablen darin zulässt oder nicht.
void Work();
}
public class AnonymousTry {
public static void main(String[] args) {
Workables w = new Workables() {
static int x = 10;
public void Work() {
System.out.println("Working..."+x);
}
};
w.Work();
}
}
< /code>
Ich kann ohne Fehler in Eclipse ausführen. Aber konnte nicht in Online -Compilern. Ich bin verwirrt darüber, ob die anonyme innere Klasse statische Variablen darin zulässt oder nicht.