DEV Community

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

Posted on • Edited on

3

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.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay