say I wanted to add pointers to java by creating a class such asthis (a pointer
ID: 3615596 • Letter: S
Question
say I wanted to add pointers to java by creating a class such asthis (a pointer of type A):class A* {
private A data = null;
public void assign(A x) {data = x;}
public A deref() {return data;}
A*(){};
};
Now suppose A is a java class with method "m" that has a sideeffect on the object and consider the following code:
A x = new A(...);
A* p = new A*();
p.assign(x);
(p.deref()).m();
Here, pointer p points to the object named by x and p is used toinvoke a method. Does this modify the object named byx? Answer in one or two sentences.
Also, what if A is a primitive type, such as int? Do A* objectsseem like pointers?
Explanation / Answer
//Hope this will helpyou.Yes, this will modify the object named by x.
If A is primitive type, it will not seem like pointers.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.