Object (computer science)

In Object-oriented programming, an object is an instance of a Class. Objects are a collection of variables and functions. 

Variables (also known as fields) have a name and a value. Variables in an object have a keyword, like public or private, which sets if a variable is able to be changed directly by code outside the object. This is known as an access specifier. Variables in an object are usually set to private, meaning that code cannot access or change information about an object from outside the object (it cannot be seen). Instead, private data is changed by using functions.

Functions (also known as methods) are things that objects are able to do. Functions also have access specifiers. Objects can use these class methods in order to change information inside of an object. This is done to keep other parts of a program from accessing information in an object freely. A group of functions in a class/object can be referred to as an interface.

 Examples 
A specific person having a bank account would be considered an instance of a bank account. The bank account would be the object. This bank account has a current balance, but it also has a history of things that were done. To keep track of the history, a data structure like an array could be used. Current balance and history would be private variables. In order to access these variables or change them, there would be methods like deposit(), withdraw(), and checkBalance(). Most applications (and other objects) only change or access this object through an interface. 

Banks usually impose a credit limit. Suppose, there are 1000 dollars on the account. If the client does not have a special agreement with the bank, he cannot take out more money than there is on the account; so he can withdraw() a maximum of 1000 dollars. He might have an agreement with the bank, so he can borrow money from the bank (but has to pay a fee). In that case, he might be able to withdraw 1500 dollars (or 2000 dollars). So the withdrawal method has to do a lot of checks as described above.
The account manager might see the account differently, she might have methods to set the maximum amount that can be taken out of the account, or to set the fee or interest rate that the customer has to pay for the money to be borrowed.

As an object is an instance of a class; it has certain things from that class. It can perhaps be compared to other objects of that class. Two apples, one red and bigger, the other green and smaller. On the other hand: It is not that easy to compare different objects. A green apple does not have much in common with a steel wrench.
 Related pages 
 Class (programming)

 Other websites 
 The Java Tutorials: Object-oriented programming concepts

Category:Object-oriented programming