Difference between Static Method and Non Static Method.
|
Static
Method |
Non
Static Method |
|
Class method. |
Instance
Method. |
|
It has static
Keyword. |
It does not
contain any static keyword. |
|
It can be
called without creating an object. |
We need to
create an object of class for calling non static method. Classname objectname=new Classname |
|
Way to call
static method in same class MethodName(); |
Way to call non
static method in same class Objectname.MethodName(); |
|
Way to call
static method in another class AnotherClassName.MethodName(); |
Way to call non
static method in another class Anotherobjectname.MethodName(); |
|
Syntax public static void methodName() { //Method Body } |
Syntax Public void methodName() { //Method Body } |
|
Less Memory is
used. |
Much Memory is
used. |
|
It can access
only static members and can not access non static member. |
A non static
method can access both static as well as non static member. |
0 Comments