What is the difference between static (class) method and instance method?

Solution:

static or class method instance method
1)A method that is declared as static is known as the static method. A method that is not declared as static is known as the instance method.
2)We don't need to create the objects to call the static methods. The object is required to call the instance methods.
3)Non-static (instance) members cannot be accessed in the static context (static method, static block, and static nested class) directly. Static and non-static variables both can be accessed in instance methods.
4)For example: public static int cube(int n){ return nnn;} For example: public void msg(){...}.
0 answers