0

If a object is an instance of a class and instance is same as object as i see on the net what is then instance of an object? Am really confused with this term instance i read a lot of definitions of instance and real world examples and i can't understand it confusing me a lot.

And to be sure i understood the term reference of an object..Reference is a pointer on object managed by CLR. Pointers are chunk of memory that points on another chunk of memory. And reference types are types of data accessed through a pointer(reference) ?

2
  • 1
    The term instance of an object simply doesn't make sense. Where did you see it? Chances are it's a mistake. Perhaps someone said "instance of object", as object is the name of a particular class in C# and several other languages. Commented Sep 4, 2013 at 15:47
  • As far as reference types go, your understanding, though somewhat oversimplified, is correct. Commented Sep 4, 2013 at 15:54

5 Answers 5

5

object is a C# synonym for the System.Object class. An instance of an object is an instance of the System.Object class. All classes extend System.Object, any instance of a class is an instance of object.

Sign up to request clarification or add additional context in comments.

Comments

2

Say you have a class Foo. When you want to create a Foo object you instantiate it like so:

Foo myFoo = new Foo();

Now the object stored in the variable myFoo is an instance of the class Foo.

It just so happens that you can also say Foo is an instance of object, meaning System.Object because all classes in C# derive from it, but it's not a particularly helpful thing to say.

Comments

0

A class describes something - akin to a template - whilst an object is an instance of it.

For example, I might have a class called "car". It describes how a car starts, and that it has four doors, but you can't start its engine: it's just a description.

Using this class, the factory builds my car (they create my object for me). With this car, I can then start its engine and drive it away.

In terms of code, I would define car as:

  public class Car {

      public int Doors { get { return 4; } }

      public void StartEngine() {
          // start engine
      }

  }

The factory then makes it for me:

  Car MyCar = new Car();

I then drive it away:

  MyCar.StartEngine();
  MyCar.DriveAway();

Comments

0

Object is a contiguous block of memory that stores the actual information that distinguishes this object from other objects, while an instance is a reference to an object. It is a block of memory, which points to the staring address of where the object is stored. Two instances may refer to the same object. Life spans of an object and an instance are not related. Therefore an instance could be null. Once all instances pointing to an object is removed, the object will be destroyed.

Comments

0

Grammatically, I agree that 'Instance of an object' sounds tautological. Instance of 'object' would be better. However, it makes more sense if you think of 'object' as meaning 'the object class' as explained by dasblinkenlight.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.