0
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
5 ответов
0
I see, but why do you need to name it anything at all?
0
Oh thank you, that makes sense now! Sorry for late reply!
- 1
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
- 1
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
- 1
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)