Java Online Compiler
Static Method
Static


class StaticDemo
{
static int x=20;
static void show()
{
System.out.println("x value is "+x);
}
}
class Demo
{
public static void main(String args[])
{
StaticDemo.show();//we can access with calss name
System.out.println(StaticDemo.x);
}
}

Static Block


class StaticDemo
{

static 
{
int x=10;
int y=20;
int z;
z=x+y;
System.out.println(z);
System.exit(0);
}
}