What is class and object?

In Object-Oriented Programming (OOP), we often hear two important terms:
Class and Object.

Let us understand these terms in a very simple way.


Example: Mobile Phone

Imagine the CEO of Samsung plans to launch a new mobile phone after 2 years.
Before manufacturing starts, the CEO discusses the features and functions of the mobile with the team.

Future Mobile: Samsung SG-786
Features (Attributes)
  • Screen size = 3.5 inch
  • Touch screen = Yes
  • Number of buttons = 7
  • Charging points = 2
  • Color = Red / Silver / Black

( means the list is long)

Functions (Behavior)
  • Make a call
  • Receive a call
  • Send SMS
  • Receive SMS

  • Alarm
  • Calculator
  • Stopwatch

Class and Object Explanation

To manufacture the mobile phone, all the above details are sent to the factory.

  • These specifications (features + functions) are called a Class.
  • When the factory produces 10,000 mobile phones using these specifications,
    each mobile phone is called an Object.

So:

  • Class → Design / Blueprint / Template
  • Object → Real product created from the class

One More Simple Example

Suppose you have one house blueprint.

  • The blueprint is a Class
  • If you build two houses using the same blueprint,
    those houses are Objects

Class in Programming

When we write a program:

  • Attributes are called Fields or Member Variables
  • Behavior is written as Methods (Functions)

A class contains:

  • Fields (data)
  • Methods (actions)

An object uses the class to work.


In short:

  • Class = Blueprint
  • Object = Instance of the class

Hope this makes the concept of Class and Object clear for beginners.