Answered step by step
Verified Expert Solution
Question
1 Approved Answer
If you return a reference to an object which happens to be a method - local variable, the return happens before the method s local
If you return a reference to an object which happens to be a methodlocal variable, the return happens before the methods local variables are destroyed. So you can create an object in your method and return it knowing the calling method will have use of the object you just created. This is because when your local object reference is destroyed, the calling method has a to your object so the JVM will not destroy it since it has an active reference to it
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started