Our Best Offer Ever!! Summer Special - Get 3 Courses at 24,999/- Only. Read more
Hire Talent (HR):+91-9791 444 054

General

Static Keyword in Java

Static Keyword in Java

Static Keyword in Java

Static key word by using we can declare variables ,methods and blocks. These static variables , methods and blocks we can access or call directly with out creating object. It means static it is class level.

Example 1:

Public class Test{
Static int i =10;
}

The above static variable in another class we can call directly with out creating the object.

Test.i; in this way we can call.

Example 2:

Public class Test{
Public static void getDetails(){
System.out.println(“static method”);
}
Static{
System.out.println(“static block”);
}
}

The above class declared static block and static method. the static block will execute directly wile creating an object before created all static blocks will execute. The static method we can call directly with these class reference with out creating an object.

Click Here-> Get Java Training with Real-time Projects

Besant Technologies WhatsApp