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 6476447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:49:36+00:00 2026-05-25T06:49:36+00:00

I read many articles and all says Java is pass by value. But i

  • 0

I read many articles and all says Java is pass by value. But i still don’t construe the difference between pass by value and reference. I wrote a sample program and it executes like this..

public class PassByValue {

   private int a;
   private int b;

   public PassByValue(int a, int b) {
    this.a = a;
    this.b = b;
   }

   public static int mul(int a, int b) {

       int z = a * b;
       System.out.println("The Value of Z inside mul: " + z);
       return z;

   }

   public static void main(String args[]) {

    int z = 100;

        int x = 40;
        int y = 20;

    mul(x,y);

    PassByValue pass = new PassByValue(x,y);
    mul(pass.a,pass.b);

        System.out.println("The Value of Z" + z);

   }

}

Execution

800
800 and 
100

Can anyone explain me these questions…

  1. What is Pass By Value means…

Answer: Its just passing the numbers or value stored in the variable to a function. Am i right or wrong.

  1. How do you say Java is Pass By Value?
  2. Why is Java is Pass By Value and not by reference?
  3. Does the above program Tries shows an example of Pass by value and Reference… but still does things via Pass by Value only… I wrote that program.
  • 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-05-25T06:49:37+00:00Added an answer on May 25, 2026 at 6:49 am

    You are right in your answer, but you are lacking detail. If you do

    Dog d = new Dog()

    d is a reference to an instance of Dog, i.e. What pass by value means is that you when pass d into a method

    walkDog(d);

    the a copy of the reference (i.e. the value of the reference, not the reference itself) to the Dog is passed into the method. So you have 2 references to the one instance of the Dog, the one in the calling scope, and the one in the called scope. Lets say in the walkDog method there is a line

    d = new Dog();

    the d reference in the method only points to the new Dog. The original reference where the method was first called still points to the original Dog. If Java had pass by reference, the same reference, not a copy of the reference would be used in the method, and so changing the value of the reference would affect the reference in both the calling and the called scope.

    EDIT — based on your comment, I want to make on thing clear. Since the reference in the original scope and the method scope both point to the same object, you can still change things on that object in both scopes. So if you do

    d.drinkWater();

    in the walkDog method, and drinkWater changes some variable on the dog object, then since both references point to the same object, which was changed.

    It’s only a distinction between what the references actually are in each scope. But it does come up a lot.

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

Sidebar

Related Questions

read many posts about the difference between the 3 idioms. But got more confused,
I've seen many many articles on how to read XML into a JTree but
I've read many different articles/threads on this, but have yet to determine the best
I read quite some articles about fragments, but I am still confused about how
I have read many articles about XML parsing in Android. However, all of them
I read many and many and many articles on WCF security etc... but i'm
I tried to read many articles on dofactory , wikipedia and many sites. I
I've read through many of the questions on SO about this, but many answers
I have read so many articles about integration and yet i did not found
First of all, the static keyword. I've read several articles and past threads on

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.