0

Explain static methods ??with examples

24th Feb 2017, 2:55 PM
0000
2 Réponses
+ 9
A static method can be invoked without creating an instance (object) of the class. For a dynamic method you need to instantiate an object to access it: // static method MyClass.method(); // or even just method (); // if you import the class // dynamic MyClass myClass = new MyClass(); myClass.method();
24th Feb 2017, 3:01 PM
Tashi N
Tashi N - avatar
+ 1
Just to add on to @Tashi's answer. Static methods belong to the class so no matter how many objects you make of that class they will all share that particular method. Lot of people are consfused with this behaviour.
24th Feb 2017, 5:22 PM
Ousmane Diaw