This is one
of the basic question of Java. In Java everything is an Object, but a Class is used to make it. The exact
definition is that "A class is a blueprint for an object".
Particularly it tells the JVM about how to make the Object.
A class is a blueprint of an Object, it mean that every Object in Java made from that class is practically the same but can have its own specific values. Like whenever a building is made, then a blueprint is made beforehand. The blueprint defines the structure of the building, but using the same blueprint you may create many separate buildings. Each building can have its own color on the walls, its own particular size, etc. But the overall structure will be the same.
Take one more example to clarify my point. We know that the process of making a car is totally automated. Now the cavity which molds the shape of the car is the same, but the same cavity is used to mold several cars. Like in the Mercedes factory, each Mercedes coming out from the car molding cavity will be practically the same. Though each Mercedes can later be given its particular color, alloy wheels, extra bumper, advanced music system, etc. Here the cavity which molds the car is the "class" in Java, and the Mercedes car coming out from that cavity is the "Object" in Java.
Now you would be easily able to visualize the difference between a class and an Object in Java. I hope that this article was beneficial in helping you distinguish between an Object and a Class.
What is an Object?
Java is totally built on the fundamental of Object Oriented Programming(OOPS), and OOPS depend upon the understanding about the "Object". So getting a hold on this question is important.
Start with real life examples, everything that you can see in this world is an Object. Just look around yourself, your bike, table, chair, television, even you yourself and me too are Objects. Every entity is an Object. Now Objects have two basic properties. They are:
1. State
2. Behavior
Whenever you need to access and understand an Object, just ask yourself what are the possible state of this Object and what could be the possible behavior of this Object. For example a table lamp can have two states on and off, while there could be two possible behavior of the table lamp, turn on and turn off.
Similarly for a cat the possible states could be hungry, color, breed, etc. While there could be many states like wagging tail, chasing mouse, etc.
The state of an Object defines what the Object "knows", and the behaviour of the Object defines what the Object "does". In Java a class is used for making an Object. Whatever the Object knows are its instance variables and whatever the Object does are its methods.
The methods In Java operate on the Objects state and provides a mechanism to the outer world to access and operate on them.
A class is a blueprint of an Object, it mean that every Object in Java made from that class is practically the same but can have its own specific values. Like whenever a building is made, then a blueprint is made beforehand. The blueprint defines the structure of the building, but using the same blueprint you may create many separate buildings. Each building can have its own color on the walls, its own particular size, etc. But the overall structure will be the same.
Take one more example to clarify my point. We know that the process of making a car is totally automated. Now the cavity which molds the shape of the car is the same, but the same cavity is used to mold several cars. Like in the Mercedes factory, each Mercedes coming out from the car molding cavity will be practically the same. Though each Mercedes can later be given its particular color, alloy wheels, extra bumper, advanced music system, etc. Here the cavity which molds the car is the "class" in Java, and the Mercedes car coming out from that cavity is the "Object" in Java.
Now you would be easily able to visualize the difference between a class and an Object in Java. I hope that this article was beneficial in helping you distinguish between an Object and a Class.
What is an Object?
Java is totally built on the fundamental of Object Oriented Programming(OOPS), and OOPS depend upon the understanding about the "Object". So getting a hold on this question is important.
Start with real life examples, everything that you can see in this world is an Object. Just look around yourself, your bike, table, chair, television, even you yourself and me too are Objects. Every entity is an Object. Now Objects have two basic properties. They are:
1. State
2. Behavior
Whenever you need to access and understand an Object, just ask yourself what are the possible state of this Object and what could be the possible behavior of this Object. For example a table lamp can have two states on and off, while there could be two possible behavior of the table lamp, turn on and turn off.
Similarly for a cat the possible states could be hungry, color, breed, etc. While there could be many states like wagging tail, chasing mouse, etc.
The state of an Object defines what the Object "knows", and the behaviour of the Object defines what the Object "does". In Java a class is used for making an Object. Whatever the Object knows are its instance variables and whatever the Object does are its methods.
The methods In Java operate on the Objects state and provides a mechanism to the outer world to access and operate on them.