Sunday, September 26, 2010

What is object in c++ and java?

This programming languages use mainly two types of memory in RAM.They are heap memory and stack memory. 
In c++ when we write <class name> <object name> then <object name> acts as a referrence variable and points to some location in stack memory... The location where the referrence variable is pointing is called object and the variable is known as referrence variable... As almost everything in c++ follows static allocation technique so object is created in stack memory.
In java we write 
Statement 1:<class name> <object name>;
Statement 2:<objct name>=new <object name>();
As you all know that new operator in both c++ and java are used for dynamic allocation so here also object is dynamically allocated in heap memory and as there is no new operator in statement 1 so the referrence variable is in stack memory... That means the memory space in the heap memory, where the referrence variable refer to from stack memory, is known as object. 
And so in java the referrence variable is known as object referrence and after performing statement 2 that object space in heap memory is known as object instance.

For any queries contact me.
My email id: anumoysengupta@yahoo.co.in

No comments:

Post a Comment