Static variables in Static Classes

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
cjgiron
Posts: 13
Joined: Fri Sep 09, 2022 5:03 pm
Contact:

Static variables in Static Classes

Post by cjgiron »

Hello,

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

admin
Site Admin
Posts: 10398
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Static variables in Static Classes

Post 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.

cjgiron
Posts: 13
Joined: Fri Sep 09, 2022 5:03 pm
Contact:

Re: Static variables in Static Classes

Post 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?

admin
Site Admin
Posts: 10398
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Static variables in Static Classes

Post by admin »

This change occurred in Java 16, since 1z0-819 is based on Java 11, this change is not applicable to that exam.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests