+ 5

Why we are using static keyword before all methods? Is it necessary? What is the use and importance?

17th Jan 2017, 12:23 PM
N.Neeharika Reddy
N.Neeharika Reddy - avatar
5 Respuestas
+ 2
by using static infornt of a method u can call that method directly by the class name, without declaring the instance of the class
4th Feb 2017, 12:12 PM
Rahul Bhat
Rahul Bhat - avatar
+ 1
Static methods are conceptually the same as static variables, thus the reasons to use or not use them are similar. They belong to the class, not specific objects of that class. An example from the java API is Math, all the variables are static.
19th Feb 2017, 5:55 AM
Prabhat kumar
Prabhat kumar - avatar
0
I think of static methods as Class methods, not Object methods. They are useful when you do not need an instance of an object for logic to complete, or you can pass an object to work with as a parameter. Class itself may have static fields and properties, for example to track count or pool of instances of an object. For example Convert.ToInt32 is a static function, you can use any string object as a parameter. It would be awkward for String object to have all possible conversion functions as non static methods. Even more, some non static methods simply call static version of that method, so all real logic is contained in static one.
7th Feb 2017, 11:46 AM
Ugnius Soraka
0
in these examples they use static to enable methods to be called within Main, because you cannot call non static within static method.
11th Feb 2017, 11:09 AM
Sandile Nene
Sandile Nene - avatar
- 2
if you use static keyword you dont have to create new object before using it.
17th Jan 2017, 5:07 PM
Hakkı Karahan
Hakkı Karahan - avatar