Junior — Middle
What types of objects can be in a data stack?
sobes.tech AI
Answer from AI
In a data stack (stack), primitive data types and references to objects are usually stored, but not the objects themselves. In Android and Java, objects are placed in the heap, while the stack stores the addresses of these objects and local variables.
Thus, the stack can contain:
- Local variables of primitive types (int, boolean, float, etc.)
- References to objects
Example:
void method() {
int a = 10; // stored in the stack
MyObject obj = new MyObject(); // obj is a reference in the stack, the object is in the heap
}