What's diff between instance method & static method ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What's diff between instance method & static method ?

8th Jan 2017, 4:58 PM
Henil Mamaniya
Henil Mamaniya - avatar
9 Answers
+ 13
Instance method = the method can only be used if you've instantiated (created) the object first. Static method = the method can be used without creating an instance of the object. Useful if you for example want to use the method within the same class.
8th Jan 2017, 8:43 PM
Emil Westin
Emil Westin - avatar
+ 7
thanx guyz got my answer
9th Jan 2017, 2:02 AM
Henil Mamaniya
Henil Mamaniya - avatar
+ 6
Methods and Variables that are not declared as static are known as ' instance ' methods and variables...static methods, variables belong to the whole class, not just an object ( instance of a class ).you can't access to instance variables or call instance methods in static methods from the same class.you can access static methods by using class name and a ' . ' after that ( or by refrence to an object of that class ), but you can only access instance methods within an object refrence....
8th Jan 2017, 7:11 PM
Masoud Farmani
Masoud Farmani - avatar
+ 6
instance method only can be called after initiation of an object and its functionality is related to this object. let's say we have class class Person { public string Name {set;get;} public void Walk (){ // walk } } Person per1 = new Person (); Person per2 = new Person (); per1.Nmae = "Alex"; per1.Walk (); per2.Name = "Sara"; so now Alex will walk but sara not. ____________________ but static method called from class name and no need to initiate object like Math class we say Math.Pi , Math.Sin (), Math.Pow () and no need to say Math m = new Math ().
8th Jan 2017, 7:13 PM
Ahmad Hamdan
Ahmad Hamdan - avatar
+ 3
In instance of method you first create object and then use method of that class and in static method you don't need to create object before calling method.
13th Jan 2017, 11:39 AM
Ravi Verma
Ravi Verma - avatar
+ 2
For example, the main method in a Java program is always static so it doesn't need to be instantiated.
9th Jan 2017, 6:23 PM
ein siedler
ein siedler - avatar
+ 1
init
7th May 2022, 10:17 AM
ANBARASU S
0
first of all I want to say that instance method is the one which is available throughout the class & can be called at any moment... whereas static method is the one where special permission is required to call it from the object created..
10th Feb 2017, 8:19 AM
Debjyoti Burman
Debjyoti Burman - avatar
0
__init__
28th Mar 2023, 11:36 PM
المهندس أحمد
المهندس أحمد - avatar