An object is the combination of related states and behavior in which variables are just like states and the methods are just like behaviors (providing some functionality). In an object, variables store values for later use and methods are the unit of codes that provides a particular functionality. We can say objects are the basic units of the object-oriented programming.
Objects are the part of our day to day life, these are the real world entities around us. Technology, records, human beings, and even the implemented concepts all are the examples of objects. For instance, A CEO of any company can take a view of his company's policies, employees, buildings, records, and beneficial packages as the objects. Similarly a software developer does analysis, designing, coding, testing and also looks for the future scope of that project as objects. Even a toy is an object for a child.
Real-world objects share two characteristics: They
all have state and behavior.
For instance Lions have state (name, color, breed, hungry) and behavior (roaring, fetching etc). Cars also have state (current gear, current speed) and behavior (changing gear, changing speed, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming. Objects are key to understanding object-oriented programming. Just look around and you'll find a lot of examples of real-world objects: cat, desk, television set, car, pen etc.
Here is an additional information about Objects that we can create multiple objects in any single java application to perform many task like implementing a GUI, any operation on information and many more.
If we consider above example of car then if we need to create a new car, we have to make a new instance or an object by using the new keyword. The constructor is responsible for setting up the initial state of an object. Instead of declaring an object, a constructor is called automatically when the new keyword is used.
A simple example of constructing an object is given below:
Here is the Code of the Example :
Here is the Output of the Example :
It's a example of car
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: May 25, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles