Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:44:00+00:00 2026-06-11T21:44:00+00:00

While coding, I have encountered a strange Java Compiler behaviour. When compiling the class

  • 0

While coding, I have encountered a strange Java Compiler behaviour.

When compiling the class (source below), the compiler emits an error (“inner classes cannot have static declarations“) on the NULL class variable. This is as expected!

However, no error is generated on the ZERO class variable. This I don’t understand!

Why this difference, which seems to allow static declarations of simple types, but not Objects, in inner classes.

(javac -version: 1.6.0_24)

public class Outer {
    public static final Runnable HELLO = new Runnable() {
        // No compiler error
        public static final int ZERO = 0;

        // Causes compiler error: "inner classes cannot have static declarations"
        public static final Object NULL = null;

        @Override
        public void run() {
            System.out.println("Hello " + ZERO + NULL);
        }
    };
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:44:01+00:00Added an answer on June 11, 2026 at 9:44 pm

    The problem is that inner classes cannot have a static initialiser block which is required to initialise non-trivial constants and non-constants.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I encountered a strange issue while coding a .dll file in C with gcc
I have an application that uses java se and while coding it I installed
I have encountered a, so it seems to me, strange behaviour of the WinAPI.
I have a system for users to apply for driving permit. However, while coding
I'm a Java Developer wich is learning VB.net for a small project. While coding
I have search around regarding this whitespace area while coding with html. But I
I'm currently coding my design portfolio and have encountered a problem with the layout.
In the Oracle PL/SQL , I have this coding, it gives me complier error.
I have the coding shown below where I have sheduled to get a http
As I'm coding for both Windows and Linux, I have a whole host of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.