Home > DeveloperSection > Forums > Difference between static methods and instance methods in Java
Royce Roy
Royce Roy

Total Post:134

Points:938
Posted on    April-15-2015 12:09 AM

 Java Java 
Ratings:


 1 Reply(s)
 416  View(s)
Rate this:
What is difference between static methods and instance methods in Java


Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Supported
Posted on    April-15-2015 12:49 AM

Static Method:
1)A method i.e. declared as static is known as static method.
2)Object is not required to call static method.
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;}

Instance Method:
1)A method i.e. not declared as static is known as instance method.
2)Object is required to call instance methods.
3)static and non-static variables both can be accessed in instance methods.
4)For example:
 public void msg(){...}.

Don't want to miss updates? Please click the below button!

Follow MindStick