+ 1
Plz explain these lines to me
The first stage of the life-cycle of an object is the definition of the class to which it belongs. The next stage is the instantiation of an instance, when __init__ is called. Memory is allocated to store the instance. Just before this occurs, the __new__ method of the class is called. This is usually overridden only in special cases.
3 ответов
0
I assume this is Ruby.
To have an object, first define its class. You can’t have tom without having Person.
This step involves writing code defining what a Person is and can do.
Then you create an object by doing tom = Person.new(“tom”)
Now what happens is behind the scenes. The new method creates the object (sets aside memory for it in the computer), then automatically calls the init method on the newly created object before you’ve done anything with it. In this case, init tells tom that its name is “tom” (tom.name == “tom”).
Now the object tom is good and ready to go.
0
it's python
0
Okay sorry about that, but I believe the answer still holds other than the syntax