Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Passing

  Asked By: Bill    Date: Nov 09    Category: Java    Views: 535
  

how can i make a passing by refrence in Java..function like swap??

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Rocco Anderson     Answered On: Nov 09

its all pass by reference. nothing is passed by value in Java unless
its a primitive datatype, such as int.

Be careful.

If you do not intend to alter the variable which was passed, make a
copy of it.

 
Answer #2    Answered By: Scott Simmons     Answered On: Nov 09

class test
{
public void swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
}

public static void main(String args[])
{
test t1=new test();
int a=10;
int b=20;
t1.sawp(a,b);
System.out.print(a);//will not change print 10
System.out.print(b);//will not change print 20
}

 
Didn't find what you were looking for? Find more on Passing Or get search suggestion and latest updates.




Tagged: