Difference between static and instance method

Java Predefined & User defined Methods, Java String Methods, Java Number Methods, Java Array Methods and Java Character Methods. Java User defined methods with return a value, User defined methods without return any value, and Java Static & Non-static Methods.
Post Reply
AyubHussain
Posts: 138
Joined: Fri Nov 23, 2018 2:48 am

Difference between static and instance method

Post by AyubHussain » Thu Nov 29, 2018 10:22 am

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

ramya
Posts: 89
Joined: Fri Nov 23, 2018 2:55 am

Re: Difference between static and instance method

Post by ramya » Thu Nov 29, 2018 10:25 am

static or class method :

1)A method that is declared as static is known as the static method.

2)We don't need to create the objects to call the static methods.

3)Non-static (instance) members cannot be accessed in the 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 that is not declared as static is known as the instance method.

2)The object is required to call the instance methods.

3)Static and non-static variables both can be accessed in instance methods.

4)For example: public void msg(){...}.

Post Reply

Return to “Java Methods”