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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:18:49+00:00 2026-06-13T09:18:49+00:00

I have an issue, while trying few code snippets i came across a code

  • 0

I have an issue, while trying few code snippets i came across a code

class O
{
    final int i;
    O()
    {
        i=10;
    }
    O(int j)// error here as THE BLANK FINAL FIELD i IS NOT INITIALIZED
    {
        j=20;
        System.out.println(j);
    }
}
class Manager3
{
    public static void main(final String[] args) 
    {
        O n1=new O();
        //O n2=new O(10);
        //n1.i=20;
        //System.out.println(j1.i);
    }
}

but if i comment the constructor with parameter i do not get any errors.

My question is why am i getting this compile time error when i put both the constructor in code and why i dont get any error when i remove parameterized constructor.

I know that we have to initialize my final variable, but i am initializing it in constructor thus if i write this code :-

class O
{
    final int i;
    O()
    {
        i=10;
    }

}
class Manager3
{
    public static void main(final String[] args) 
    {
        O n1=new O();

    }
}

every this is working fine and code is compiling.

My question is what is the issue if i introduce another constructor. Even the error is at the line where i write parameterized cons.

I have understanding of JAVA but i am confused in this code.

  • 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-13T09:18:51+00:00Added an answer on June 13, 2026 at 9:18 am
    final int i;
    

    You have defined i as final. You can assign values to final variables only in constructors.

     O(int j)// error here as THE BLANK FINAL FIELD i IS NOT INITIALIZED
        {
            j=20;
            System.out.println(j);
        }
    

    Here you are not assigning value for i. If someone uses this constructor (constructor with parameter) to create an object, i value won’t be assigned.

    How to resolve this?

    As you said, either you have to comment this constructor (or) assign i value inside this constructor as you did in other constructor.

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

Sidebar

Related Questions

Alright, while designing a site, I came across a thought... I have a few
I have ran into an interesting issue while trying to create a more usable
I have a somehow funny issue. While trying to understand why a certain website
I'm trying to debug an issue. We have few Threads that work on data
I've been stuck on this issue for a while. What I have here is
I have an issue while getting the file name with out extension from a
I have an issue while storing some special character values into db. For e.g.
I have an odd issue while using FlashCS4. I have a textfield that, when
First of all: I'm at Scala 2.8 I have a slight issue while using
We have implemented webservice which generates xml response. I am facing issue while invoking

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.