Why is child = Child() nessasary?
See comments, is this just convention or for readability? This was an example code snippit illistrating classes https://code.sololearn.com/c5psb57Pb0qy/?ref=app https://code.sololearn.com/c5psb57Pb0qy/?ref=app
9/25/2017 12:43:01 AMBridget McKenzie
5 AnswersNew Answer
I see, but why do you need to name it anything at all?
Oh thank you, that makes sense now! Sorry for late reply!
class parent is the first class class child(parent) is the 2nd defined class inherited from parent class.. ## the features parent have ; child will have too now child=child() means...child is a variable of child() class type u can name it anything...like abc=child() here we are injecting all properties of class child() in abc
see.... in object oriented programming . we have a hell lot of variables... they have different but some of alike properties... so we have suppose 60 variables... how would u inject all needed properties in them... here we make certain class... certain inherited class and make the variables as they are of that class... ## hope u now get that ## once they are injected of certain class properties... we can use them in the further more codes
and....this two are different things .... Child().hello()........1 child = Child() child.hello()............2 1 is just accessing hello method of Child class 2 is making a var of Child class and then using the property of that variable... now hello is a property / feature of whatever variable u named it..(abc or child)