This content has been marked as final. Show 1 reply
say we have below method
Public void test1(int i, AccountInfo accInfo)
CustomerInfo custInfo = new CustomerInfo();
In above case CustomerInfo object will be created on heap but its reference i.e custInfo will be stored in stack. Correct?
Except that when you say "its reference," it sounds like it has one single reference which is inherently tied to it. That is not the case. This particular reference (the one stored in the custInfo varible) will be on the stack.
Same is true for object parameters (like accInfo) but prmitive type method will be stored in stack right?All method parameters and all local variables are on the stack. If the method parameter or local variable is a reference type, then the object it points to will be on the heap.
Note that there is no such thing as an "object parameter," in that no parameter (or local variable) ever has an object as its value--only a reference.