answersLogoWhite

0


Best Answer

References are equal if they both point to the same object.

o2);

// true because they are meaningfully equal

System.out.println(o1.equals(o2));

}

}

Meaningfully equal is defined by overriding the equals method of class Object.

boolean equals (Object obj) Decides whether two objects are meaningfully equivalent.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the diff between equality of objects and equality of references that refer to them?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why is an array of reference not possible?

Unlike pointer variables and other variables, references have no storage of their own. A reference is simply an alias for an object that already exists in memory (allowing you to refer to the object by its memory address). Since they have no storage of their own it is impossible to create an array of references. You can of course create an array of objects, each of which can then be referenced. You can also have several references to the same object. But you cannot store those references because there is nothing to physically store other than the object itself, which is already stored. For the same reason you cannot reference references nor can you point to references. You can only refer and point to objects (or point to NULL of course).


What is difference between Deep copy and shallow copy?

A "shallow" copy is when the member values are physically copied from one object to another, *including* the values of any pointer or reference members. If there are pointer or reference memebrs, then, those poointers or references refer to the *same* objects as the original object, which is usually a bad thing. That's why you want to define a copy constructor and assignment operator for objects that contain pointers or references. It's called a "shallow" copy because only the values of the pointers/references are copied, instead of making copies of those referred-to objects and setting pointers to them. *That* is what would be called a "deep" copy, because it's going "deeper" into the structure, copying everything, not just the first "layer".


What is aggregation in C plus plus?

Aggregation and composition are two sides of the same coin. Both an aggregate and a composite object encapsulate one or more sub-objects. But while a composite object owns its sub-objects, an aggregate object does not. That is, when a composite object is destroyed, its sub-objects are also destroyed. But with an aggregate object, the sub-objects are not destroyed. Aggregate objects typically use references or pointers to refer to their sub-objects, whereas composite objects typically use member variables or pointers to refer to their objects. In essence, a composite object instantiates its own sub-objects, whereas an aggregate object's sub-objects must be passed to it, typically via the constructor. In complex models you will often find a combination of composition, aggregation and inheritance, even within the same object.


Do dangling references and garbage ever arise in the same programming language?

Dangling references and garbage, otherwise known as memory leaks, can occur in the same application and programming language. These symptoms are evidence of sloppy memory management by the programmer.Dangling references and garbage collection cannot normally occur at the same time, as the garbage collector is not supposed to discard an item so long as there are still any references to it. Therefore, a reference can never "dangle" (i.e. refer to a no longer existing item).


Write a program to copy the value of one string variable to another variable?

You can have two String variables (note that String variables are object references) refer to the same String object like so: String str1 = "Hello"; String str2 = str1; Now the str1 and str2 are references for the same String object containing the word "Hello". If you actually want a new String object with a copy of the contents of the original String, you use the String constructor that takes a String argument, like so: String str3 = new String(str1); Now str1 and str3 refer to SEPARATE String objects that happen to contain the same sequence of characters (the word "Hello"). Since Strings objects in Java are immutable, they can be shared without worrying about the contents used by one variable being upset by the use through another variable as might happen with char[] arrays in C or C++ so the first method is probably sufficient for most cases.

Related questions

Why is an array of reference not possible?

Unlike pointer variables and other variables, references have no storage of their own. A reference is simply an alias for an object that already exists in memory (allowing you to refer to the object by its memory address). Since they have no storage of their own it is impossible to create an array of references. You can of course create an array of objects, each of which can then be referenced. You can also have several references to the same object. But you cannot store those references because there is nothing to physically store other than the object itself, which is already stored. For the same reason you cannot reference references nor can you point to references. You can only refer and point to objects (or point to NULL of course).


What Is the different between Brilliant unit and satin unit?

What sort of objects does this refer to?


What is the difference between reference and hash code in java?

Cat oldCat = new Cat(); Cat newCat = new Cat(); Cat oldCatRef = oldCat; In the above example, oldCat and oldCatRef are references to the same object. Since they refer to the same object, their hashcodes will be equal. But oldCat and newCat do not refer to the same object. They are references to two different objects. But they might have the same hashCode based on their implementation. hashCode is simply a method in Object class which you can override.


Demonstrative pronouns usually refer to objects rather than?

Demonstrative pronouns usually refer to objects rather than people.


Demonstrative pronouns usually refer to the objects rather than what?

Demonstrative pronouns typically refer to objects or things, such as "this," "that," "these," and "those," to point out or identify them. They do not generally refer to people or concepts.


What is difference between Deep copy and shallow copy?

A "shallow" copy is when the member values are physically copied from one object to another, *including* the values of any pointer or reference members. If there are pointer or reference memebrs, then, those poointers or references refer to the *same* objects as the original object, which is usually a bad thing. That's why you want to define a copy constructor and assignment operator for objects that contain pointers or references. It's called a "shallow" copy because only the values of the pointers/references are copied, instead of making copies of those referred-to objects and setting pointers to them. *That* is what would be called a "deep" copy, because it's going "deeper" into the structure, copying everything, not just the first "layer".


Are cell column references letters or numbers?

Letters refer to columns.


What are the difference between among and between?

Difference between Among and Between : Among is used when we talk about things which are part of a group or mass of objects. Between is used when we refer to two things which are clearly separated.


Difference Between RPC and RMI?

The only real difference between RPC and RMI is that there is objects involved in RMI: instead of invoking functions through a proxy function, we invoke methods through a proxy.What this means in practice is that we now want the client to hold references to remote objects that it can invoke methods on. These references should behave just like local objects, but when invoked dispatch the method invocation to the remote object.Because we need to refer to both an object and a method now - not just a function - we extend the protocol so it first sends an object id across the socket, then the method and then the arguments. The server then dispatches the method to the remote object based on id and method name.-Rituparno Ganguly


What is aggregation in C plus plus?

Aggregation and composition are two sides of the same coin. Both an aggregate and a composite object encapsulate one or more sub-objects. But while a composite object owns its sub-objects, an aggregate object does not. That is, when a composite object is destroyed, its sub-objects are also destroyed. But with an aggregate object, the sub-objects are not destroyed. Aggregate objects typically use references or pointers to refer to their sub-objects, whereas composite objects typically use member variables or pointers to refer to their objects. In essence, a composite object instantiates its own sub-objects, whereas an aggregate object's sub-objects must be passed to it, typically via the constructor. In complex models you will often find a combination of composition, aggregation and inheritance, even within the same object.


Lyndon Johnson used the term justice rhetorically to refer to?

Economic and social equality


Pronouns that refer to inanimate objects are in what gender?

neuter