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 7611743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:44:19+00:00 2026-05-31T01:44:19+00:00

Why aren’t final variables default initialized? Shouldn’t the default constructor initialize them to default

  • 0
  1. Why aren’t final variables default initialized? Shouldn’t the default constructor initialize them to default values if you are happy with the constant be the default value.

  2. Why must you initialized them in the constructor at all? Why can you can’t you just initialize them before using them like other variables?

ex.

public class Untitled {

public final int zero;

     public static void main(String[] args)
     {
          final int a; // this works
          a = 4; // this works, but using a field doesn't
          new Untitled();
     }
}

Untitled.java:2: variable a might not have been initialized
  1. Why must you initialize static final variables when they are declared? Why can’t you just initialize them before using them in any other method?

ex.

public class Untitled
{

      public final static int zero;

      public static void main(String[] args)
      {
           zero = 0;
      }
}

Untitled.java:8: cannot assign a value to final variable zero

I’m asking these question because I’m trying to find a logical/conceptual reason why this won’t work, why it isn’t allowed. Not just because it isn’t.

  • 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-05-31T01:44:20+00:00Added an answer on May 31, 2026 at 1:44 am

    The idea behind a final variable is that it is set once and only once.

    For instance final variables, that means they can only be set during initialization, whether at declaration, in a constructor, or an instance initialization block. For the variable to be set anywhere else, that would have to take place in a non-constructor method, which could be called multiple times – that’s why this is off limits.

    Similarly for static final variables, they can only be set at declaration or in a static initialization block. Anywhere else would, again, have to be in a method which could be called more that once:

    public static void main(String[] args)
    {
         zero = 0;
         main(null);
    }
    

    As for your first question, I’m assuming it’s an error not to explicitly set a final variable in order to avoid mistakes by the programmer.

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

Sidebar

Related Questions

Destructors aren't virtual by default to not hurt when its not needed, which is
My expression aren't great and I would like to improve on them so I
I know that key-value pairs aren't good database design, aren't normalized etc however in
My variables aren't producing data like they should be. For whatever reason, my string
The numbers themselves aren't relevant. I have a list of variables that are used
Why aren't copy constructors chained (like default ctors or dtors) so that before the
The elements aren't positioning themselves as I want them to. I want the picture
For some reason duplicate values aren't eliminated. records = Records.objects.all() records2 = records.values_list('columna','columna').distinct() print
Aren't Javascript blocks supposed to execute in the order that they are placed on
Why aren't many commercial, 3D video games (not random open source 2D ones) written

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.