how to use a method in static method code example

Example 1: what is static method

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

Example 2: instance method and static method

static or class method
1) A method that is declared as static is known as the static method
2) We don't need to create the objects to call the static methods
3) Non-static (instance) members cannot be accessed in static context 
(static method, static block and static nested class) directly.
4) For example: public static int cube(int n){
return n*n*n*; (multiply *) }

Instance method
1) A method that is not declared as static is known as the instance method.
2) The object is required to call the instance method.

Tags:

Java Example