Neighter in Java nor in C++ you can't access variables n
and path
before you create an object of type Print
. In what kind of memory an object will be created, in the same kind of memory would be created all it's fields.
In C++, when you create object like this
void foo() {
Print obj;
}
it will be created in stack. And if you create an object like this
void foo() {
Print * obj = new Print;
}
it will be created in heap.
In Java you can create only heap-allocated objects, so both object itself and it's fields will be placed into heap.
Pay an attention, that initializing class's fields in declaration allows only in C++11, not in C++03