Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:33:37+00:00 2026-06-08T18:33:37+00:00

I think I understand that it is a copy of the object/data member passed

  • 0

I think I understand that it is a copy of the object/data member passed into the method tricky(), as only the value is what matters, not the actual object itself. But the print statements assure me that arg1 and arg2, the copies, are indeed switched within the method. I don’t understand why this wouldn’t relay the information back to original objects, consequently switching them; Seeing as the method is able to successfully access the arg1.x and arg1.y data members within the method.

// This class demonstrates the way Java passes arguments by first copying an existing
// object/data member. This is called passing by value. the copy then points(refers)
// to the real object

// get the point class from abstract window toolkit
import java.awt.*;

public class passByValue {


static void tricky(Point arg1, Point arg2){

  arg1.x = 100;
  arg1.y = 100;
  System.out.println("Arg1: " + arg1.x + arg1.y);
  System.out.println("Arg2: " + arg2.x + arg2.y);

  Point temp = arg1;
  arg1 = arg2;
  arg2 = temp;
  System.out.println("Arg1: " + arg1.x + arg1.y);
  System.out.println("Arg2: " + arg2.x + arg2.y);
}




public static void main(String [] args){

  Point pnt1 = new Point(0,0);
  Point pnt2 = new Point(0,0);
  System.out.println("X1: " + pnt1.x + " Y1: " +pnt1.y); 
  System.out.println("X2: " + pnt2.x + " Y2: " +pnt2.y);
  System.out.println(" ");
  tricky(pnt1,pnt2);
  System.out.println("X1: " + pnt1.x + " Y1:" + pnt1.y); 
  System.out.println("X2: " + pnt2.x + " Y2: " +pnt2.y);  

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:33:38+00:00Added an answer on June 8, 2026 at 6:33 pm

    Java does pass by value, but what it passes is the value of the object’s reference, which gives the effect of pass by reference (for primitives, it behaves more like pass by value).

    But Java is always pass by value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think that is not easy to understand what I need reading title, so
Ok I understand that this error mostly comes from sending a method call or
When should retain be used ? I understand that it increments the object references
I'm looking at a way to clone an object that is not known at
So I'm trying to find a generic extension method that creates a deep copy
Does the normal functions (and not the static ones) have only one copy for
I am new to using numpy and one thing that I really don't understand
I'm sorry that I haven't deeply understood HBase and Hadoop MapReduce, but I think
I think understand the idea of duck typing, and would like to use it
I think I understand the logic behind a delegate. I got more the problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.