What functions do the substitution operators for objects do?

Asked 2 years ago, Updated 2 years ago, 21 views

Let me get straight to the point. For example,

class alpha{
   //omitted below
        .
        .
        .    
}

There's a code like this.

public void main (String[] args) {
    alpha temp1 = new alpha;
    alpa temp2 = temp2;
}

If there is a code like this, will temp1 and temp2 point to the same object on the memory? Or just two objects with the same value?

Whoo...Originally, there are many things that I can't adapt to because I usually dig C language and then transfer to JAVA.

java

2022-09-21 19:59

1 Answers

Point to the same object.

It's easy to think it easy. Everything that uses the new operator in Java is created in heap. Think of it as using malloc in c.

class object name; This declaration is a reference, and I think the pointer is the closest to c.

In other words, the code is weird in the question..

alpha temp1 = new alpha (appropriate value);
alpha temp2 = temp1;

When temp1 and temp2 point to the same object.


2022-09-21 19:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.