You should see: The Stack Is An Implementation Detail, Part One and Part Two By Eric Lippert
1 - Where the object emp stored in memory i.e in stack or heap and how ?
On heap, because its a reference type since Employee
is a class.
2 - Where the name and age variables stored in memory and how?
They are also stored on heap. Although age is a value type, but value types are stored where their container reference is stored.
3 - What does each word in this statement do i.e what does employee
do..then emp..then =.. then new.. then employee.. then ()..then ;
Create a new instance of Employee
class named emp
4- What is the difference between the above statement and Employee
emp; ? Tell in terms of memory allocation.?
Employee emp;
means just declaration, not instantiation. That means no memory is allocated to the object and it will hold null
.