I'm trying to do some practice for an exam and need some help (did I do them correctly? If not, why?) on these problems about java primitives and java objects. These are all true or false.
The following variable declaration is a reference to an object which is dynamically allocated and stored in the heap: int x = 7;
False, because it is pass by value since int is primitive
The following variable declaration is a reference to an object which is dynamically allocated and stored in the heap: Integer x = 7;
True, because it is referencing an object stored on the heap
If you pass the variable ‘x’ as declared in (1) to a method, that variable is passed by reference, and its value may be modified by the called function.
False,because Java only does pass by value
If you pass the variable ‘x’ as declared in (2) to a method, a copy of that variable is created in the heap, and passed to the function, so that the function’s object reference is pointing to a distinct place in memory.
True, because variable is in the stack but it is pointing to a place in the heap
Thank you all for the help.
(4) is false for two reasons: