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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:47:52+00:00 2026-06-15T10:47:52+00:00

Java uses pass-by-value, both with Objects and primitive types. Because Java passes the value

  • 0

Java uses pass-by-value, both with Objects and primitive types. Because Java passes the value of the reference, we can change the value of target but cannot change the address.

How does this compare with C++?

  • 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-15T10:47:53+00:00Added an answer on June 15, 2026 at 10:47 am

    The difference is whether you can affect a variable in the calling function.

    Let’s leave objects aside for a moment. In Java, which is purely pass-by-value, you can’t change the calling function’s value of a variable passed into a called function. Example:

    void foo() {
        int a = 42;
        bar(a);
        System.out.println("foo says: " + a);
    }
    void bar(int a) {
        a = 67;
        System.out.println("bar says: " + a);
    }
    

    If you call foo, you’ll see:

    bar says: 67
    foo says: 42
    bar could not change foo’s a.

    That’s true in C++ if you pass by value. However, if you pass by reference, you’re passing a reference to the calling code’s variable. And that means the called code can change it:

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

Sidebar

Related Questions

I know that Java doesn't really use exact pass by reference, but rather pass
My Java applications uses Hibernate with a SessionFactory-scoped interceptor in order to change data
Possible Duplicate: Is Java pass by reference? I have a question about passing by
I hava a java application that uses Buffers to pass object around between threads.
I want to pass arguments to a java application but like linux application style.
MyClassWithMainMethod.java uses classes of someJar.jar. If I call: java -cp someJar.jar MyClassWithMainMethod I get
My Project has 2 java files (A.java and B.java in same package). A.java uses
I heard C, C++, Java uses two complements for binary representation. Why not use
My Android application uses Java OAuth library, found here for authorization on Twitter. I
I'm developing a Java application that uses java.util.logging for its logging needs. This application

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.