Data Flow Diagram

Data Flow Diagram
Project:- Hospital Management system

Tuesday, October 18, 2011

static keyword in java


/*

static:doesn’t require the object of class to

access the member of that class and access the member of

that class with the name of class directly

*/

///example for static member function and data of class

class Mclass
{
         private static int a;
         static int b;
          public Mclass(int x)   {
                  a=x;
           }
         public static void funStatic() {
                   System.out.println("this is static method");
                   System.out.println("static variable : "+a++);
                   System.out.println("static variable : "+b);
            }
           }
class Sclass
{
    static void funmain()
    {
            System.out.println("this is static method in main");
    }
   public static void main(String args[])
     {
           Mclass m1=new Mclass(10);
           funmain(); //doesn't require the object to access
          Mclass.b=20; //static variable is accessed
             Mclass.funStatic(); //call directly from class nam
         }

}

No comments:

Post a Comment