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: 14
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?

Online
admin
Site Admin
Posts: 10058
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.
If you like our products and services, please help us by posting your review here.

cjgiron
Posts: 14
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?

Online
admin
Site Admin
Posts: 10058
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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: admin and 36 guests