DEV Community

Cover image for Stuck with Class and Object in OOPS?
Enakshi Pal
Enakshi Pal

Posted on • Updated on

Stuck with Class and Object in OOPS?

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 color, 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, color 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 behaviors. 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.

A code snippet is given, explaining class and object.

Top comments (0)