Showing posts with label java static modifier. Show all posts
Showing posts with label java static modifier. Show all posts

Java- static modifier / Chapter -6/ Access Modifier



Java static modifier

Java static modifier




  1. "static" is a modifier applicable for methods & variables but not for classes.(not for top-level classes but for inner classes we can apply)

  2. We can't declare top level classes with static modifier but we can declare inner classes as "static".

  3. in the case of instance variables for every object a separate copy will be created but in the case of static a single copy will be created at the class level and this will be shared by every object of that class.  example:-
    class Test

    {

          static int x=10;

          int y=20;

          public static void main(String [ ]args)

          {

               Test    t1 =new   Test( );

                t1.x =  888;

                t1.y =  999;

               Test   t2 =new Test( );

               System.out.println(t2.x +".........."+t2.y);

          }

    }

     

    output is;

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com