/    Sign up×
Community /Pin to ProfileBookmark

Pass by value or pass by reference?

These two have me very confused. I really have no idea how to figure this out when looking at code. Will someone please tell me if the following code uses pass by value or pass by reference and explain to me how they know?

[CODE]import java.awt.Point;
class PassMe
{
public static void modifyPoint(Point pt, int j)
{
pt.setLocation(5,5); //1
j = 15;
System.out.println(“During modifyPoint ” + “pt = ” + pt +
” and j = ” + j);
}
public static void main(String args[])
{
Point p = new Point(0,0); //2
int i = 10;
System.out.println(“Before modifyPoint ” + “p = ” + p +
” and i = ” + i);
modifyPoint(p, i); //3
System.out.println(“After modifyPoint ” + “p = ” + p +
” and i = ” + i);

}
}[/CODE]

to post a comment
Java

1 Comments(s)

Copy linkTweet thisAlerts:
@chazzyAug 18.2006 — in java, objects are always referenced, where elementary things (int, char, etc) are value...
×

Success!

Help @RGL spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...