Take any OOPs language with referencing as basic structure like java and c#.
For fast execution, they also support primitive types like int and char.
I think this is done by storing them on the stack.
and object types on the heap.
so for this:
class B
{
...
}
class A
{
int a;
B b;
}
Is A.a is in stack or on heap ?
The basic answer is that all local variables are on the stack and everything else is on the heap. However, as of Java 7 the compiler will perform a technique known as Escape analysis that checks whether an object is used strictly within a method (and doesn’t escape that method), and upon finding such an object, will allocate its storage on the stack. This behavior was introduced with Java 6, Update 14, but not activated by default.
This, as many other examples, shows you that Java Language Specification is one thing and implementations another. As long as an implementation behaves as defined by the JLS, it is legit.