Is my understanding correct in regards to Static? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is my understanding correct in regards to Static?

Basically, we have classes that is like the blue print for objects correct? now being that that is said. I can think of classes like vehicles and objects like specific vehicles (ie ; bw , honda , mercedes etc). Now, coming to static, static methods basically refers to methods that belong to the class and not a specific object correct? so in the vehicle example i gave above, if i had a static method that prints out "Car is a 4 door", since this method is static , does that mean all the objects mentioned in the example has a method that prints "...four doors" ? because it belongs to the class correct? Am i making sense?

26th Jul 2017, 5:52 AM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
1 Answer
+ 7
You are correct. A better example of a static object in your case would be a vehicle counter which counts the number of vehicles 'sold' (initialized). Imagine for each vehicle initialized, the static object which acts as a counter would be increased by 1. For all existing instance of the class vehicle, the counter will return the existing number of vehicles, instead of a newly initialised counter for each instance of class vehicle. Instead of reading it as : This instance of the class has properties of... It would be read as : This class has properties of...
26th Jul 2017, 6:28 AM
Hatsy Rei
Hatsy Rei - avatar