What is DIFFERENCE? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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

9th Jul 2021, 5:02 AM
saurabh
saurabh - avatar
3 Réponses
+ 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
9th Jul 2021, 5:28 AM
Aysha
Aysha - avatar
+ 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
9th Jul 2021, 6:31 AM
Aysha
Aysha - avatar
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?
9th Jul 2021, 6:00 AM
saurabh
saurabh - avatar