Static Program Example in Java
class stm
{
static int i=10;
static void add(int a,int b) //static method
{
System.out.println("sum is "+(a+b));
}}
class static1
{
public static void main(String aa[])
{
stm.add(30,51); //calling static method
int i=stm.i; //accessing the the vaiable
System.out.println("sum is "+i);
}
}
class stm
{
static int i=10;
static void add(int a,int b) //static method
{
System.out.println("sum is "+(a+b));
}}
class static1
{
public static void main(String aa[])
{
stm.add(30,51); //calling static method
int i=stm.i; //accessing the the vaiable
System.out.println("sum is "+i);
}
}
0 comments:
Post a Comment