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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:31:42+00:00 2026-06-09T13:31:42+00:00

I am preparing for a certification exam and I don’t understand this code: Main:

  • 0

I am preparing for a certification exam and I don’t understand this code:

Main:

public class TestStudent {
    public static void main(String[] args) {
        Student bob = new Student();
        Student jian = new Student();
        bob.name = "Bob";
        bob.age = 19;
        jian = bob;
        jian.name = "Jian";
        System.out.println("Bob's Name: " + bob.name);
    }
}

Class:

public class Student {
    public String name = "";
    public int age = 0;
    public String major = "Undeclared";
}

Why does this output “Bob’s Name: Jian”?

Bob.name was never set to Jian. Obviously it must be because “jian = bob;” but i thought that would only set jian variables to the same as bob. What is this concept called and where is it explained in java tutorials?

  • 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-09T13:31:43+00:00Added an answer on June 9, 2026 at 1:31 pm

    Assignments in Java do not copy objects, they copy references. After this assignment

    jian = bob;
    

    your jian is no longer pointing to the Student object that you have allocated and assigned to jian, it’s the same as bob, creating an alias to the same object. The original jian is now irretrievably lost, becoming eligible for garbage collection.

    The following assingment

        jian.name = "Jian";
    

    overwrites the name in the bob variable through its jian alias, leading to the result that you see.

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

Sidebar

Related Questions

I'm preparing to SCJP and looks like I don't understand class cast principles. class
In preparing to a OOP exam, I enjoyed seeing g++ compile the following code
Preparing for exam and got stuck at this question: Allowed operators are <<,+,& no
Hi i am preparing for an exam and i am stuck with this What
I'm preparing data for a datatable in Linq2Sql This code highlights as a 'Possible
I'm preparing to do an .NET exam and I came across this question. I
I am currently preparing myself for the exam in Networking and I got some
I am preparing for my interview and came across this question: Consider that i
While preparing for the SCJP-6 exam I faced with a difficult issue. I can’t
I am preparing for my interview tomorrow -- I need the answer to this

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.