+ 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)....

2nd Aug 2016, 7:10 AM
eugene dakarapu
eugene dakarapu - avatar
3 Antworten
+ 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.
2nd Aug 2016, 7:41 AM
James
James - avatar
0
any demo program??
2nd Aug 2016, 6:15 PM
eugene dakarapu
eugene dakarapu - avatar
0
wrote in in the apps code playground
2nd Aug 2016, 11:07 PM
James
James - avatar