user2076685
user2076685

Reputation: 31

stack and heap diagram of method that is assigned to reference variable

How could we draw the stack and heap diagram of following code:

Ball b1;
Ball b2 = new Ball();
Ball b3 = new Ball();
b1= doThing();
b3 = doThings();

I know call methed (e.g doThing()) will be in stack. how relate b1 (which is in stack to doThing()). should we create an object in heap for them?

Upvotes: 1

Views: 529

Answers (1)

Sergey Morozov
Sergey Morozov

Reputation: 4608

All java-ojbect created in heap. If doThing() instantiate Ball then we should create an object in heap for them on diagram.

Upvotes: 1

Related Questions