Don't let the Lockdown slow you Down - Enroll Now and Get 3 Course at 24,999/- Only. Explore Now!

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

Scroll Up
Besant Technologies WhatsApp