Can anybody tell me, if the c'tor d'tor calling works the same way with polymorhism, as I instatiate a derived class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anybody tell me, if the c'tor d'tor calling works the same way with polymorhism, as I instatiate a derived class?

e.g. Animal dog = new Dog(); So: C'tor(Animal) C'tor(Dog) D'tor(Dog) D'tor(Animal) Thaks for every useful answers!

18th Apr 2016, 1:56 PM
Gábor Beke
Gábor Beke - avatar
1 Answer
+ 2
Yup. Dog.Finalize (the destructor) will be called first and then call Animal.Finalize, no matter whether you pass the Dog around as Dog or Animal or Object. :)
25th Apr 2016, 11:22 PM
Schindlabua
Schindlabua - avatar