14th May 2020, 7:25 AM
🎶💞Sravs💞🥀
🎶💞Sravs💞🥀 - avatar
3 ответов
+ 1
class Swapper{ int a; int b; Swapper(int x,int y){ a = x; b = y; } void swap(int a,int b){ int temp; temp = a; a = b; b = temp; } } class SwapDemo{ public static void main(String args[]){ Swapper obj = new Swapper(10,20); System.out.println("before"+obj.a+obj.b); obj.swap(obj.a,obj.b); System.out.println("after"+obj.a+obj.b); } } you cannot use star next to variables like in c or c++ for pointers. i removed the star characters and the code runs fine.
15th May 2020, 10:50 AM
Sebastian Pacurar
Sebastian Pacurar - avatar
+ 1
But this code is call by value but I want to pass reference to variable
15th May 2020, 12:03 PM
🎶💞Sravs💞🥀
🎶💞Sravs💞🥀 - avatar
0
15th May 2020, 12:06 PM
Sebastian Pacurar
Sebastian Pacurar - avatar