Greeting for the day!
I have a question in my mind and looking for answer from some days.
If my understanding is correct then only diff between Instance and object is :-
instance means just creating a reference(copy) .
object :means when memory location is associated with the object( is a runtime entity of the class) by using the new operator
Now i want to know how to create an instance of an object.
Please give explanation with sample code
Any help will be appreciated.
Thanks
By your explanation it’s not called an instance, but a reference of an object. An instance of a class is called an object. I think your question is: “What is the difference of an object and a reference variable?” I’ll try to explain it with some examples:
I just declared a reference variable. This is not an object but only a reference that refers to an object.
Now I created a new object and assigned it to the
freference variable so every time I do something tofI refer to theFooobject. Like when I callf.Name = "MyFoo";I refer to the foo object.Now I declare another reference variable.
What we have here now is having ONE object in the memory but TWO reference variables refering to the same object.
This last line will return true because we changed the
IsFooproperty totrueandfandotherFooreffer to the same object.I hope that explains you everything. 🙂