Page 1 of 1

Static variables in Static Classes

Posted: Tue Sep 13, 2022 10:47 pm
by cjgiron
Hello,

In static nested classes, do static variables still need to be marked final?

Re: Static variables in Static Classes

Posted: Tue Sep 13, 2022 11:32 pm
by admin
No, they do not need to be marked final. There never was such a restriction on static nested classes.

Before Java 16, non-static nested classes i.e. inner classes were allowed to have a static field only if that field were final. This restriction has been removed in Java 16.

Re: Static variables in Static Classes

Posted: Fri Sep 16, 2022 6:27 pm
by cjgiron
I see. So does the 1Z0-819 test reflect this change? Or should I still stick to the rule that non-static inner classes can only have a static field if it is final?

Re: Static variables in Static Classes

Posted: Sun Sep 18, 2022 12:18 am
by admin
This change occurred in Java 16, since 1z0-819 is based on Java 11, this change is not applicable to that exam.