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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:10:29+00:00 2026-06-07T04:10:29+00:00

I am reinitializing the member variable of a local class and am getting a

  • 0

I am reinitializing the member variable of a local class and am getting a compilation error. What is wrong here? Why will this not compile? Thanks!

This will not compile

public class TestSomething {

public void someMethod(){
    class LocalClassInner{
        int i=100; // Error on this line.Syntax error on token ";", , expected

        i=200;
    }       
}

}   

This compiles just fine

public class TestSomething {

public void someMethod(){
    class LocalClassInner{
        int i=100;
        //i=200;
    }       
}}
  • 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-07T04:10:30+00:00Added an answer on June 7, 2026 at 4:10 am

    This isn’t really an local class problem. You can’t put assignment statements at the “top-level” of any class.

    Assignment statements need to go in a method, constructor, static initializer, or instance initializer.

    WHen you wrote

    int i = 100;
    

    you were actually declaring a field of the inner class (as you know). You can reassign this field, provided you did so in a constructor, method, etc.

    ADDENDUM

    The following uses an instance initializer, just for fun:

    public void someMethod() {
        class LocalClassInner {
            int i = 100;
            {i=200;}
        }           
    }
    

    It compiles fine, see http://ideone.com/qjnv3

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

Sidebar

Related Questions

In this question of mine , @DeadMG says that reinitializing a class through the
In jQuery when you do this: $(function() { alert(DOM is loaded, but images not
Since this is a huge post here is a short summary (please read the
In a recent project I had to create a Singleton class and after a
I ran into a interesting issue today. Check out this pseudo-code: void Loop() {
Update Turns out the error was in the crypto processor code, that is fixed.
I haven't worked with reinitializing a subscription for SQL Server 2005 replication before and
here is an example of what I am doing Page Load { //Adds items
After parsing JSON data in a Data class, I set the UIViewController's NSArray *headlines
I have this problem with Cocoa, I am calling a function and passing an

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.