+ 1
void method will not return any value but why do it will return a value when creating a variable inside the void method what does that mean a little bit confusing can you explain?? for example void set(int x)....
3 Réponses
+ 1
it's not returning a value, it's setting a value. Difference being when you call the method. If you had another variable y for example and tried to do int y = set(x); and the set was void, you would get an error because it doesn't return the value of x in the method. What's happening, is the classes x value is being changed, so if you were to call the variable directly with class_object.x, you would get the new value.
Created a program as demonstration, look up pickle in the playground.
0
any demo program??
0
wrote in in the apps code playground