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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:47:34+00:00 2026-06-14T22:47:34+00:00

From what I have learned, the class objects in Java are actually references to

  • 0

From what I have learned, the class objects in Java are actually references to those objects. An object itself cannot have a variable, only a reference to it.

Consider the following C++ example :

SomeClass A(5);
SomeClass &B = A;
SomeClass &C = B;

Now, I think I’m right in saying that all of the three statements below will use the exact same object :

A.someMethod(); //some object
B.someMethod(); //the same object
C.someMethod(); //the same object

However, in Java, although objects are actually references, using the assignment operator will create an entirely new object with a new reference to it.

SomeClass A = new SomeClass();
SomeClass B;
B = A;

Now, the method calls will call from entirely different objects :

A.someMethod(); //uses one object
B.someMethod(); //uses entirely different object

Please tell me whether I am right or wrong.

  • 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-14T22:47:36+00:00Added an answer on June 14, 2026 at 10:47 pm

    References are different from objects. A particular object can have more than one reference pointing to it. When calling a method of a class at compile time always the class reference is checked whether the reference type contains the method defined in its class. If not a compile time error is issued. If the method is overridden in a subclass of the given class then the overridden method is called at run-time. At compile time always ‘class-ref’ in <class-ref>.method() is checked to see whether it contains the method definition. Other modifiers like static, final, abstract, method visibility are also checked at compile time itself and a compile time error is issued if the wrong combination of method modifiers is used.

        SomeClass A = new SomeClass();
        SomeClass B;
        B = A;        // Same class, same object, different reference
    
    
    A.someMethod(); //uses one object
    B.someMethod(); //uses the same object
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I come from a Java background, but I learned C++ after and have been
I just learned that an object can have only one ID, so I'm not
I have learned from the sencha doc how to create a simple MVC application,
I have learned from various tutorial that If a client can reasonably be expected
In my studies, I have learned that if you want to prevent users from
I learned of gist.github.com from Mozilla Ubiquity , and have been using it to
I have a library function that returns a list of domain objects from a
EDIT From what I have learned (from comments by nico_ekito) it is not possible
I'm writing a Java application that will instantiate objects of a class to represent
I don't have much experience doing unit testing. From what I learned, code should

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.