Class and Object in non technical approach

Posted By :Keshav Agarawal |28th June 2019

Consider below images as real-world entity â€¦

If I ask you what is this?

you will say it’s a Watch…. right!!…

let's go ahead, so what is this?

you will say, this is a house…. right!!

Actually, the first picture is not of a watch.

The second pic is not a whiteboard.

And the third pic is not a house…  now you are thinking, what is wrong with me? 

Wait…just for a few minutes, the first pic is actually not a watch. then what it is?

It is actually a “Type of Watch” or you can say it is something which looks like a watch.

The second pic is not a whiteboard. It is a type of whiteboard.

The third pic is not a house, it is a type of house.

But how? let see….

These are blueprints of the house.

Assume this is your house blueprint. How will you feel after seeing it? You will feel “this is my house” or “my house will look like this” …. I hope… right…. let’s go ahead :)

So the pic what you are seeing is not “watch, whiteboard, house”, they are just type of watch, type of whiteboard and type of house.

The “type” is actually an Object and “name (watch, whiteboard…)” is actually a class.

As par OOPS, Class is a blueprint or a road map, which is used to create a set of homogeneous product and these homogeneous products are known as Object.

see the above house blueprint, if I build houses on the basis of this blueprint, all house will be the same.Alternatively, you could argue the entire house will be homogeneous.

Now, in Java, a class is a non-primitive data type that is used to categorise objects. The class also define the behavior and properties of an object.

So what are behavior and properties?

Let understand it by an example…..

If I ask you like who are you (name) or where do you live (city) … it represents property and if I ask you like what do you do (a method), it represents behaviour….

In the same way, a class defines properties (variable) and behavior (method).

I hope this is clear.

Now let understand about Object….

Everyone knows an object is an instance of a class.

Is that sufficient? I don't think so….

Then what is Object? Well, an object is a memory allocated inside a heap area at run time. The object does not have any name but they have a physical address.

Now you will not agree that object does not have any name… wait for a second.

Let me take an example…. Tell me one thing…the person who is reading this answer or who was writing this answer is an object or a class…… yes, they all are object.. Very good…

If we object, we have a name, correct? However, I mentioned that the object lacks a name.

Well, let me prove this...

In this world, there is lots of space. A kid is born.

When this kid born, it covers some space in the world and it does not have any name. But it has a relation with his father. So what doctor says, you got a beautiful kid. ( that means there is relation but does not have a name) ==> name is given to this kid after some time. In the same way, let consider this example

What is a Person? A Person is essentially a class.

Class Person {

}

Right…

How we create an object?

Person p = new Person( ) ;

Here “ new Person( )” creates an object…that means memory will be allocated at runtime.

So what is “p” here…its a reference variable or object name…. So basically "p" is associated with this object [ new Person() ]

I hope now you understand what is class and what is object :)

you can refer this link as well: https://www.quora.com/What-is-the-difference-between-class-and-object-in-OOP/answer/Keshav-Agarawal


About Author

Keshav Agarawal

Keshav Agarawal is Java Developer with skilled in Java, Servlet, JSP, JDBC, Spring Boot, Spring MVC, JPA, Hibernate. His hobbies are playing chess and reading books in free time. By nature he is friendly and honest person.

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us