DIFFERENCE BETWEEN STATIC METHODS AND INSTANCE METHODS IN JAVA

Royce Roy

Total Post:149

Points:1043
Posted by  Royce Roy
Java 
 742  View(s)
Ratings:
Rate this:
What is difference between static methods and instance methods in Java
  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: Difference between static methods and instance methods in Java

    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(){...}.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!