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

  • Home
  • SEARCH
  • 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 6997493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:17:25+00:00 2026-05-27T20:17:25+00:00

I tried to run this program but this gives a runtime error(StackOverflowError). If in

  • 0

I tried to run this program but this gives a runtime error(StackOverflowError). If in class Static I make reference object ob, static, then no error occurs. Can anyone please explain me why is this happening and please explain me how are field variables(whether static or non static and whether reference or non reference variables) initialized?

public class Static {

    public Static ob = new Static();
    private int a;

    public void win(Static obj) {
        //System.out.printf("ob.a = %d\n", ob.a);
        obj.a = 15;
        System.out.printf("ob.a = %d", ob.a);
    }
}

public class StaticTest {

    public static void main(String args[])
    {
        Static obj=new Static();
        //Static obj1=new Static();

        // obj.win(obj1.ob);
    }
}
  • 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-27T20:17:25+00:00Added an answer on May 27, 2026 at 8:17 pm

    Your code creates an instance of Static class.
    When the instance is create their attributes are initialized. What your code does is to initialize the ‘ob’ attribute with pointing to a new Static instance.
    Then the new instance of Static class is created, and … you have an “infinite initialization loop”.

    If you attach ‘static’ keyworkd to an attribute you are creating a “class attribute”, that is, an attributed shared among all instances of that class.
    This means when you execute code and the first instance of Static is goind to be created JAva initialize the ob attribute. Subsequent instances of Static doesn’t initialize it because it is shared among all.

    See this sample: http://www.roseindia.net/java/beginners/staticvariable.shtml

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

Sidebar

Related Questions

Error I tried this page to run on local, it is running perfectly fine
When I run this code the selected item is not visible. I've already tried
How do I run this command with subprocess? I tried: proc = subprocess.Popen( '''ECHO
I have tryed to run this code in my console: script/plugin install git://github.com/apotonick/cells.git ...but
I tried to run 2 JQuery-ajax at the same time, but it's seem always
I received the following error when I tried to run a C# WinForms application
I'm attempting to run mongrel_rails, but I get the following: the program can't start
Whenever I exit my program it gives me this exception 0xC0000022: A process has
I want to run some commands via a remote program. I've tried it using
I'm having some issues with the old Cannot make a static reference to a

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.