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

The Archive Base Latest Questions

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

on passing object reference to static method m1() why it does not become null

  • 0

on passing object reference to static method m1() why it does not become null and why last statement doesn’t give errror. Output is X

 class I {
        private String name;
        public String name() {            
            return name;
        }
        public I (String s) {            
            name = s;            
        }
    }

    class J {
        public static void m1 (I i){
            i = null;
        }
        public static void main (String[] arg)
        {
            I i = new I("X");
            m1(i);
            System.out.print(i.name());
        }
    }
  • 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-10T10:24:54+00:00Added an answer on June 10, 2026 at 10:24 am

    Java is pass by value so scope of i is limited to m1()

    public static void m1 (I i){ // i is copied from i which is in main method but it is another variable whose scope lies within m1() only
    
        i = null;  // original i in main lies in main() method scope
    
    }
    

    If you change name of i in method m1(), confusion will be lesser like :

    public static void m1 (I iObj){ 
        iObj = null;  // i in main() method still points to Object
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am passing a JSON object as a reference to my custom jquery widget
Possible Duplicate: passing in object by ref With the code below, the output would
I am having some troubles passing a reference to an object which is of
If I am passing an object to a method, why should I use the
When I'm trying some code to learn about passing a reference of an object
I know when we are passing objects we are passing its reference as a
I know that when it comes to passing objects in java, the reference of
I am passing an object like this: -@users.each do |user| %tr %td=link_to(user.first_name, users_user_path(user), :title
I'm passing an object from jQuery to a MVC3 Controller via a $.ajax POST.
I am passing an object from one asp.net page to another. I'm encoding the

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.