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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:27:47+00:00 2026-05-27T15:27:47+00:00

I know that if you pass a Class type as a parameter for a

  • 0

I know that if you pass a Class type as a parameter for a method the pointer will be passed and if you edit the parameter in the method you also edit the original object instance you passed (for example if a method named public void changeColor(Color color) does the following code:

public void changeColor(Color color)
{
    color = new Color(20, 100, 50);
}

and you called the value like so:

Color color = new Color(10, 20, 30);
System.out.println(color.toString());
changeColor(color);
System.out.println(color.toString());

both lines of the console should be different (java.awt.Color[r=10,g=20,b=30] and java.awt.Color[r=20,g=100,b=50]), thus the value is changed and the pointer is passed. On the other hand, if you use an int value, which is a primitive, you get different result:

public void changeNumber(int i)
{
    i = 10;
}

and you called the value like so:

int n = 5;
System.out.println(n);
changeNumber(n);
System.out.println(n);

The console does not print 5 and 10 but on both lines says 5. With that said, if I had this:

public class A
{
    public int i;
    public Color c;

    public A(int n, Color color)
    {
        i = n;
        c = color;
    }
}

And in the runnable class…

public static void main(String[] args)
{
    A a = new A(10, new Color(10, 40, 23));
    changeA(a);
}

public static changeA(A varA)
{
    varA.i = 54;
    varA.c = new Color(40, 30, 264)
}

Will i inside the A class also act as if it were part of the pointer of A or will the value if a.i in the main method not change after I run changeA(a); If not, what can I do so it does change?

  • 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-27T15:27:48+00:00Added an answer on May 27, 2026 at 3:27 pm

    Will i inside the A class also act as if it were part of the pointer of A or will the value if a.i in the main method not change after I run changeA(a)

    The value of i in the A instance passed as the parameter to A will change.

    But I wouldn’t say that it is acting “as if it were part of the pointer of A”. The reference to A is a single immutable value. You are changing the state of the object it refers to.

    By the way, this is not what “pass by reference” means, and it is not analogous to pass by reference as implemented in languages such as C# and C++, or the C hack of passing the address of a variable / member / whatever.

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

Sidebar

Related Questions

I know that I can pass a string as the second parameter to the
How do I declare an object of a variable type? I know that I
I know that it's a common convention to pass the length of dynamically allocated
I know from here that I can pass an ignore option in the jQuery.validate
I know that |DataDirectory| will resolve to App_Data in an ASP.NET application but is
Say I have a method that is expecting a generic collection parameter of a
I need to get the type of a property that will only be known
Let's say I have this : class whatever(object): def __init__(self): pass and this function:
I am writing a simple class that will basically accept 3 parameters, execute a
I want to create a new class that is a special type of string.

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.