Friday, August 11, 2017

Tricky facts about Static variable

Facts about static and non-static variables

package com.javaserialization;

public class TestStatic {

     /* non-static variable can reference to static variable */
     static int c = 10;
     int d = c;

   /* static variable can't reference to non-static variable */

     int a = 10;
     static int b = a;

     public static void main(String[] args) {
          TestStatic test = new TestStatic();
          System.out.println(test.d);
     }
}


No comments:

Post a Comment