You are on page 1of 1

class StaticClass

{
static String name="Preeti"; /*static variable (static blocks and static
variables are initilised or implemented
in the order they are written in
code) */
static int age=21;
static int marks;

StaticClass() //constructor
{
marks+=50;
}

static //static block


{
System.out.printf("name:%s%nAge=%d%nmarks:%d%n",name,age,marks);
marks=marks+100;
}
static void display() //static method of class,needs to be called
by using class name i.e classname.display()
{
System.out.printf("marks:%d",marks);
}
}
class Object
{
public static void main(String[]args) // static method of class
Object(priority less than static block )
{
new StaticClass(); //creating object of StaticClass
StaticClass.display();
}
}

You might also like