0
what is the difference between static function and non static function? Example?
4 Answers
+ 1
The main difference is stattic function must call using class name and non static function must call using object reference
0
can u plz give an example? BDW thanx for responding.
0
static functions can only be called from a static context and need no object references, in this way the can be accessed statically using the syntax Class.foo() therefore no need to instantiate the class
0
non static (instance) functions operate on instances (objects) and u call them on one object and they do stuff with that object, like:
object.getStuff(); //returns stuff for that object
static functions aren't object based, they can be calld even if object isn't created and mostly they do thing like printing number of objects created from class (can be 0, can be 10...)
Class.getNumOfObjects(); //returns stuff for that class...
u'll uderstand when to use static and when instance when u go deeper into OOP