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

  • Home
  • SEARCH
  • 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 8766387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:32:24+00:00 2026-06-13T16:32:24+00:00

This is the code I have, please look at it before you read the

  • 0

This is the code I have, please look at it before you read the question

 package ict201jansem2012;


public class Qn3b {

    public static void main(String[] args) {
        int a = 1;
        int b[] = {4,5};
        String s = "Good luck!";
        method1(b[1]);
        System.out.println("(1) b[0] = "+b[0]+"; b[1] = "+b[1]);
        method2(b);
        System.out.println("(2) b[0] = "+b[0]+"; b[1] = "+b[1]);
        method3(a);
        System.out.println("(3) a = " + a );
        method4(s);
        System.out.println("(4) s = " + s );
    }
    public static void method1(int b) {
        b = 7;
    }
    public static void method2(int[] b) {
        b[0] = 3;
    }
    public static void method3(int a) {
        a = 3;
    }
    public static void method4(String s) {
        s = "UniSIM";
    }
}

Output:
(1) b[0] = 4; b[1] = 5

(2) b[0] = 3; b[1] = 5

(3) a = 1

(4) s = Good luck!

So my question is ,
This is intresting for me to know as learning programmer. The int b array 0 index value has changed, but not the other variables like the String s and int a. Before i ran this program I roughly thought in my mind that the variable will change their values as the methods are called ,this is because the method is being called and the main method vairable such as a,s and b array are passed and then they are being modified.

So in a nutshell why is that the b array 0 index is changed while the other variables are not changed?

  • 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-13T16:32:25+00:00Added an answer on June 13, 2026 at 4:32 pm

    Java is pass-by-value, but most values (everything that’s not a primitive, in this case int[] and String) are references, which means they act like pass-by-reference.

    Here’s a nice writeup: http://javadude.com/articles/passbyvalue.htm

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

Sidebar

Related Questions

Please have a look at the following machine code ‎0111001101110100011100100110010101110011011100110110010101100100 This means something. I
i have this simple question please. I have this part of code which sets
Guys before you start down voting me please read this question and please understand
Please have a look at the following code package normal; import java.io.*; import java.util.*;
i have this quick issue please. I have this code here which permits me
Could anyone please help me convert this code to vb.net, I have tried it
I have a line of php code that looks like this: echo <script>$('#edit_errors').html('<h3><em>Please Correct
So I have this code here: <table> <tr> <td width=200px valign=top> <div class=left_menu> <div
I have tried to ask a variant of this question before. I got some
Please have a look at the following code <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools android:layout_width=match_parent android:layout_height=match_parent android:orientation=vertical

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.