* Object in c# is a pointer to the memory block that is allocated for a class.
* an object contains the reference of memory block that are created by new class_name()
* Only those things comes into object scope that member variable or function of class
* Static variable or function is not the part of object.
in c# a class is a reference type and when we declare any variable for a class then it is called a instance
ex.
Class Test
{
Test test;//instance variable
Test test1=new Test();//test-->object
}
*for a object the memory allocated into stack and provided space of 4 bite in c# and for a class memory allocated into heap and its address stored into stack and that stack block named by the object variable.
But if you are talking about c++
in c++ class is a value type that why an object does not need to have a memory block in heap
ex.
# include <iostream.h>
Class Test
{
int eid;
public:
void display()
{
eid=201;
cout <<"hello";
}
}
void main()
{
Test test;
test.display();//correct
//we can also do
Test *test;
test->display();//error , to remove the error we need to assign the memory block for class as //Test *test=new Test();
}
* an object contains the reference of memory block that are created by new class_name()
* Only those things comes into object scope that member variable or function of class
* Static variable or function is not the part of object.
in c# a class is a reference type and when we declare any variable for a class then it is called a instance
ex.
Class Test
{
Test test;//instance variable
Test test1=new Test();//test-->object
}
*for a object the memory allocated into stack and provided space of 4 bite in c# and for a class memory allocated into heap and its address stored into stack and that stack block named by the object variable.
But if you are talking about c++
in c++ class is a value type that why an object does not need to have a memory block in heap
ex.
# include <iostream.h>
Class Test
{
int eid;
public:
void display()
{
eid=201;
cout <<"hello";
}
}
void main()
{
Test test;
test.display();//correct
//we can also do
Test *test;
test->display();//error , to remove the error we need to assign the memory block for class as //Test *test=new Test();
}
No comments:
Post a Comment