Sobes.tech
Junior — Middle

Where within the structure of an object are simple (primitive) variables located?

sobes.tech AI

Answer from AI

In Java, primitive variables inside an object are stored directly within the object itself, that is, in its fields. Primitive types (int, boolean, char, double, etc.) occupy a fixed amount of memory in the object, unlike reference types, which are stored as references to separate objects in the heap.

For example:

class Person {
    int age;          // primitive field stored inside the object
    String name;      // reference field storing a reference to a String object
}

Here, age is stored inside the Person object, while name is a reference to a separate String object.

Where within the structure of an object are simple… - sobes.tech