In our previous chapters we have learned about concepts of Classes and Objects.

So a class Human will represent all humans and a class Animal will represent all Animals, and this list go on and on for all different real life objects.

And as per our definition of Objects.

An Object is an instance of a Class with unique characteristics or properties.

As we have already read that Objects are special type of variables that store information about a unit (or instance) of a class.

Let’s take an example for further understanding. Suppose you want to create a program to manage products inventory using any OOP language. A product can have these basic properties or relevant information in real life.

  • Name
  • SKU
  • Price
  • Category
  • Tax

So how would you set or add these real life properties of a product in your class? If you remember from our programming core course that we use variables to store different type of data or information in a computer program. Therefore, all OOP languages provide a way to use variables in a class. And, when we use or define a variable in a class, we use a special name for it. That is ‘Property’.

As different class objects can have different values for each property. For example, two different products, Product A and Product B will have two different values stored in property ‘Name’. And because an Object is an Instance of a Class. That’s why, we use different term when we refer to Object properties. i.e. ‘Instance Variables’. We also call these instance variable in case of Objects. Because, an Object is an instance of a class. And properties are actually variables under the hood. So our new definition will be something like this.

A property or instance variable is a way to store associated information of an object instance of a class in a computer program.

Here is a visual illustration of Classes, Objects and Properties.

We have a class Product that has five different properties to store information associated with each object of this class.

And we also have two objects of class Product. We have used different values for all instance variables of each object to explain that both objects are different. Although, there should be at least one property that should tell us or uniquely identify an object.

Let’s move on to our next chapter. Please click on ‘Next’ to continue.

Image placeholder

Hi! I'm Zeeshan Elahi

I have compiled and prepared this content with love for people like me and you. And as you know it always take some time and extra cups of coffee to read, compile and prepare a course or manual. If you have like reading this content and want to say thanks, please consider supporting from more stuff like this.

Leave a comment

Your email address will not be published. Required fields are marked *