+ 1
What's diff between instance method & static method ?
9 Antworten
+ 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.
+ 7
thanx guyz got my answer
+ 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....
+ 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 ().
+ 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.
+ 2
For example, the main method in a Java program is always static so it doesn't need to be instantiated.
+ 1
init
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..
0
__init__