Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8216467

SOError when a static variable initialization followed by instance variable initialization , both to a new object of the same class

XMLWordPrintable

    • x86_64
    • windows_8

      A DESCRIPTION OF THE PROBLEM :
      static StaticTestOne so1 = new StaticTestOne(); // reference variable marked as static
      StaticTestOne so2 = new StaticTestOne(); // reference variable marked as a non static field
      The above two lines of code were entered outside main method and in class scope and the main method was left blank. When the program was executed, it threw Java Exception from JVM and futher displayed a stack overflow error. But the program successfully executes when only one of the two statements are given. The statement with static invokes the constructor and the statement without static shows no output. But the combination of these two throws error in the form of Java Exception.


      ---------- BEGIN SOURCE ----------
      package com.statictest;

      public class StaticTestOne {

      static StaticTestOne so1 = new StaticTestOne();
      StaticTestOne so2 = new StaticTestOne();

      public static void main(String[] args) {


      }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: