0

I keep hearing the words instances and objects, don't they have the same meaning or not?

For example, if I want to initialize an object of a class, I use the new operator to initialize an object with a class.

Button button = new Button();

I have an object or instance now, don't I?

  • In practical terms, `instance` and `object` are synonymous. – mjwills Jan 03 '21 at 22:56
  • Not quite. In C# and the CLR's case you can actually have an instance of an unboxed valuetype, which is not an object. You can also have an instance of a ref pointer. – Charlieface Jan 03 '21 at 22:57
  • 1
    @Charlieface Why is an unboxed valuetype not an object? – mjwills Jan 03 '21 at 22:58
  • An object is something that inherits from `System.Object`. Only a boxed valuetype does, not an unboxed one. – Charlieface Jan 03 '21 at 22:59
  • 2
    https://stackoverflow.com/questions/1793357/do-value-types-integer-decimal-boolean-etc-inherit-from-object @Charlieface Regardless, `object` when talking in general terms is not talking about `System.Object` _specifically_. – mjwills Jan 03 '21 at 22:59
  • @mjwills I guess I come more from the CLI/CLR perspective, that an object will be on the heap. The second top answer there shows up the difference. – Charlieface Jan 03 '21 at 23:01
  • 1
    I know @Charlieface - hence why I suggested the link. You don't need to explain it to me. ;) Regardless, `object` when talking in general terms is not talking about `System.Object` _specifically_. Thus, for someone learning programming the answer to `I keep hearing the words instances and objects, don't they have the same meaning or not?` is - in practical terms they are synonymous. – mjwills Jan 03 '21 at 23:02
  • Thank you very much, it was a pleasure to communicate with you. – Sandra James Jan 03 '21 at 23:06
  • A class is a class like a recipe. An instance is an instance of a class like a cake. Object is abiguous and can mean either. – TaW Jan 03 '21 at 23:55
  • @SandraJames **An object is an instance of a class**. A class is the concept of the chair in the mind. The instance is the fact that a chair exists in the real word and is different from another chair. The object is the chair itself. Therefore an instance is a concretization or materialization of a class idea, and we call that an object. So we say that instance and object words are synonymous, keeping in mind this subtlety of the vocabulary. –  Jan 04 '21 at 06:07

0 Answers0