Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок0
What is DIFFERENCE?
v1 passed, while v2 not.. Why? What is DIFFERENCE in both? And why in v1, constructor is called only once? https://code.sololearn.com/crQYgPc6bDqW/?ref=app https://code.sololearn.com/cLtKuzG49sp6/?ref=app
3 ответов
+ 2
One thing you can't take 2 objects name same as you did in v2 program
Every object needs different name
Ex: t1, t2, t3 etc
You can use argument value same as much as you want but the object name should be different. So it was giving an error in your v2 program
In v1 you didn't give any parameter that means the default value must be the output (constructor called once)
In v2 you gave different values and made different objects so that's why you got different output (constructor called 3 times
Hope it is clear to you
+ 2
V2 is called using objects and v1 is called using functions
In main you have only called the fun function as
Fun() this is default function which have no parameters
You have done is declared constructor, functions func and display.but the main thing is you have declared x in constructor and y in display function. And func function is declared outside the class.you need to mention it inside the class and can declare both inside and outside.so that's why there is no difference in calling the func many times.you need to give same name as x in fun function to give it a desired output
So it's only giving 1 as output
Hope it is understood by you
0
Aysha what does ur explanation for v1 mean?
I didn't get it....
Also i have modified v1 now tell me what's the solution?