answersLogoWhite

0


Best Answer

Yes. If you simply write:

x = new SomeClass();
y = x;

will make the variable y refer to the same object that variable x is referring to.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can two variables refer to the same object?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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.


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.


What is type equivalence in programming language?

Type equivalence occurs when two variables are of the same type. For example, if both variables are int (integer variables), they are of equal types. Equivalence can also occur with two different types that are compatible with each other.


Quantitative variables can be separated into what two types?

nominal and ordinal is wrong; those are the two types of qualitative variables. Ratio and interval are the two types of quantitative variables.


What is the diff between equality of objects and equality of references that refer to them?

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.

Related questions

If two graphs have exactly the same shape what can you tell about the variables?

The two variables are correlated.


Can you store the two variables with different values but having same name in session object?

Yes you can store it but the value which is assigned at the last will be accessed when the value is displayed.


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.


What does Correlation of plus 1.00 mean?

It mean that there is no correlation between the two variables. The variables are the same.


Can you have two variables in the same equation with the same value?

Yes, but it is not a common occurrence.


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.


The natural frequency of an object depends on its?

It depends on two variables v : speed of sound within this object L : main lenght of this object The natural frequency of the object will be v/L


When an equation has two variables there is a number of values that the two variables could have?

If an equation has two variables, we'll call them (x,y), the variables can be any value as long as both sides of the equation have the same result. If the equation was x = y, then the variables could be (1,1), (2,2), (3,3),etc...


Which two variables show a INVERSE relationship?

For an object in motion without any acceleration, velocity and time.


A graph of two simultaneous linear inequalities in two variables that have no intersecting regions must contain two lines with the same slope?

A graph of two simultaneous linear inequalities in two variables that have no intersecting regions must contain two lines with the same slope.


What are two with the same variables raised to the exact powers?

Like terms.


What is positive Correlation?

Positive correlation is a relationship between two variables in which both variables move in tandem that is in the same direction.