Program to demonstrate static variables, methods in java

class UseStaticMember
{
    //static variable
static int x=4;

//static method
static void display()
{
    System.out.println("x : "+x);
}

}

class StaticmemDemo2
{
public static void main(String args[])
{
System.out.println("x : "+UseStaticMember.x);
UseStaticMember.display();
}
}
/*
x : 4
x : 4
*/

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|