what is the difference between static function and non static function? Example? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is the difference between static function and non static function? Example?

21st Jul 2016, 5:59 PM
saurabh upadhyay
4 Answers
+ 1
The main difference is stattic function must call using class name and non static function must call using object reference
21st Jul 2016, 6:09 PM
Kunapareddy Vj
Kunapareddy Vj - avatar
0
can u plz give an example? BDW thanx for responding.
21st Jul 2016, 6:18 PM
saurabh upadhyay
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
22nd Jul 2016, 1:23 AM
Eric Gitangu
Eric Gitangu - avatar
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
22nd Jul 2016, 4:29 PM
Petar Suvajac
Petar Suvajac - avatar