Sind statische Variablen in einer anonymen inneren Klasse erlaubt? Einige sagen nein, aber ich kann ohne Fehler in der S

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Sind statische Variablen in einer anonymen inneren Klasse erlaubt? Einige sagen nein, aber ich kann ohne Fehler in der S

by Anonymous » 24 Feb 2025, 12:12

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, konnte aber nicht in Online -Compilern. Ich bin verwirrt darüber, ob die anonyme innere Klasse statische Variablen darin zulässt oder nicht.

Top