user106168
0
Q:

Static method in java

We can declare a method as static by adding keyword “static” before method name.
Let’s see example on static method in java.

public class StaticMethodExample
{
   static void print()
   {
      System.out.println("in static method.");
   }
   public static void main(String[] args)
   {
      StaticMethodExample.print();
   }
}
2
static keyword is a non-access modifier. static keyword can be used with 
class level variable, block, method and inner class or nested class.
3
The static keyword in Java is used for memory management mainly. We can apply static keyword with
variables, methods, blocks and nested classes. The static keyword belongs to the class 
  than an instance of the class.

The static can be:

Variable (also known as a class variable)
Method (also known as a class method)
Block
Nested class
2
class scratch{
	public static hey(){
		System.out.println("Hey");
    }
	public static void main(String[] args){
		hey();
        //print Hey to the console
    }
0
A static method belongs to the class rather than the object.
There is no need to create the object to call the static methods.
A static method can access and change the value of the static variable
0

New to Communities?

Join the community