Java is an "Object Oriented Programming Language" (OOLP) which simply means that everything in a java program are essentially objects. In better words, ANY java program is a collection of objects and these objects interact with each other to achieve some specific task.
An object to java world is what an entity is to real world. Any real world entity has some characteristic attributes and behaviors. For example, a dog is a real world entity which has "one tail","two eyes","four legs",etc. as some of its attributes and which has "barking","jumping up","wagging its tail",etc. as some of its behaviors.
Quite similar to a real world entity, a typical java object has a unique state (defined by the values of its instance variables) and some functions (its methods). The states and functions that a java object can have are decided by its definition or blueprint and this blueprint is called a class.
A class defines a type in java world. Any java object is of a specific type. In order to understand it better, we can take an analogy from the real world - cars. When we say car, it conjures up a picture of something that has four wheels, four doors, which has an engine, which runs on some fuel and so on. A car is the blueprint but it does not exist physically. On the other hand, a Volkswagen Beetle is a real entity that exists. Beetle is an entity of type car or we can also say that car is a class and Beetle is an object of class car.
No comments:
Post a Comment