I have been banging my head for a while now, understanding java language. I have been familiar with classes but i always get confused with object? I know the question sounds very stupid but I am still not able to figure out what a java object do and why do we need it. How different is it from a plain variable. How to call it. How can I use a java object defined in one class into another? These questions are mocking my head for a while now.
Could someone explain object in simple sentences?
Any help with some simple example would be very much helpful.
I have been banging my head for a while now, understanding java language. I
Share
A class defines the data and behavior that all the instances (objects) of this class will have. For example, the class Dog has a name and color fields, and a
bark()method. Now if you want to make an application with three dogs, you will create three instances of the Dog class:Once you have a dog you can ask it to bark:
You could also imagine a House class, containing dogs:
So you could create a house:
add dogs in the house:
And when you come at the door of the house, all its dogs start barking:
So an object can be composed of other objects, and objects can call each others methods to assemble a whole application.