Monday , January 23 2017
Home / JAVA / Static keyword in java

Static keyword in java

Static keyword is often used in java for various purpose. Different programmers use different keyword according to their convenience and requirement However one could not move away from the fact that static keyword is frequently used in Java.projects

We can use “static” in java in three ways:

1. static method
2. static variables
3. static block

Static Method

In this we make the method of a class static which means that static method defined in class will remain same for all class.Also we can say that static methods are common for all objects. Static methods can be call through the class name ,also it can be called directly without any class name as well as object name before it.But for this case static method should be called in the same class where the static method has been defined. If we call the static method in different class than we can call it from the class name before it. Also static methods can be called from the objects in the similar manner as we call the instance methods. But static methods are common for all the objects, where as instance methods are different for all objects. Example of static function is the public static void main function of java which is static refers that this main function remains same for all objects.

static method in java

Static Variable

Static variables are common for all the objects and they have the default values defined in java .Also we can say that value of the static variables did not change while calling from different objects. But using the instance function which are different for the different objects we called in the class.

We can use instance variables and static variables in the instance methods. But we cannot use instance variables in static methods, for this we use objects.


static variable in java


Static Block

Coming Soon …




Also See:   How to Null a string or empty a string array

Check Also

Program for Matrix Multiplication in JAVA

Matrix Multiplication:– Here is given a Java Program for Matrix Multiplication also call matrix product. In ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.