+ 1
What is the output of this code? class Temp { public int num = 2; public Temp() { num++;} ~Temp() { num++; } } static void
when the object is created the constructor increments the num value by 1 and when the program ends destructors is called which again increments the value by one .So how the answer might be 3?
3 odpowiedzi
+ 4
After instantiating a new class, value in num var will be incremented, cause public Temp() - is constructor which call after object create . When object is destroyed , value incremented again, cause ~Temp() -is destructor, which call before object destroying. "static void" in the end not have any reason!
answer is 3 cause method , which show value was called before object is destroyed.
+ 2
Answer: 3
0
Please place code in the playground and post a link here.
Your question is hard to read. Because of the code in the title.
It looks like a part of the code is missing