Stuck with class and object in OOPS?

Enakshi Pal
2 min readApr 21, 2021

--

The most basic and frequently asked question on Object Oriented Programming Paradigm in any interview. If you have mentioned about OOPS in your resume, then you are most likely to get hit by this question.

What is an Object.

Before diving into the definition let us consider an example.

A pen is an object and it has a significant existence. It has many properties such as its colour, size, smoothness and so on. Likewise, a car is also an object with a significant existence and has its own properties such as size, model, colour and others.

So, an Object can be ‘anything’ around us. Be it a pen, a car, or anything which has a significant existence. Object must have some properties or attributes, which can help us differentiate one object from another.

Technically, Object is a distinguishable entity with some attributes and behaviours. An Object is an instance of Class.

Now, what is a Class.

Let us understand with an example. Before building a house, we need a plan or a design to build it properly. Likewise, here the house is an Object and the plan is the Class.

Technically, a Class is a container, which contains the contents of objects that belong to it.

An object is an instance(element) of a class.

In Java we use “new” keyword to create an object.

Following is a code snippet explaining class and object.

--

--

Enakshi Pal
Enakshi Pal

Written by Enakshi Pal

A Human Being. Dedicated to creating beginner-friendly content.

Responses (1)