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

initialization not as specified

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      From: ###@###.###
      Date: Tue, 1 Feb 2005 21:16:48 -0800

      This program is required to print 0 but prints 12.

      import java.lang.reflect.*;

      class Base {
          public static int X = readDerivedNReflectively();
          static int readDerivedNReflectively() {
              try {
                  return Derived.class.getField("N").getInt(null);
              } catch (Exception ex) {
                  ex.printStackTrace();
                  return 0;
              }
          }
      }

      class Derived extends Base {
          public static final int N = 12;
          public static void main(String[] args) {
              System.out.println(Base.X);
          }
      }

      ###@###.### 2005-2-02 05:46:45 GMT

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ahe Peter Ahe
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: