In a static method,here static is basically a keyword.This Static keyword is applied on a variable or
method.
Let us understand this by an example:
If Static Keyword is not applied then the method becomes non-static method
Purpose of static & Non-static
When we write a program,we create a variable or method which is stored in small portion of memory as
show below.
In that variable or method if static keyword is not applied,means it is non static variable or
method.Then if
we have to invoke that non-static method or variable ,we have to create an object of a class,by that
object you can invoke that method or variable.
When that non-static variable is intialized,it will make different copies again and again and store it in
memory.
When static keyword is applied on a variable or method,means it is a static variable or method.Then
if we
have to invoke that static method or variable,we don't require class object,it can be invoked using
the class name only.
It is also called as class method as it belongs to the class rather than object of that class.
Now Let us understand difference between static and non static method with the help of program.
Write a program calculate sum and difference of two numbers.