Wednesday, January 13, 2010

Objects

Objects

A class needs to be instantiated before you can use the instance variables or attributes and methods. An object is an instance of a class and is analogous to a relational table row. The instance contains the attributes, which are known as its data or state, and the methods defined in the class.

above figure shows an example of an Employee class defined with two attributes, id, which is the employee identifier, and lastName, which is the last name of the employee, and the getId() and setId(String anId) methods. The id attribute and the getId() method are private, and the lastName attribute and the setId(String anId) method are public.

When you create an instance, the attributes store individual and private information relevant only to the employee. That is, the information contained within an employee instance is known only to that particular employee. The above figure shows two instances of the Employee class, one for the employee Smith and one for Jones. Each instance contains information relevant to the individual employee.

source:-http://download.oracle.com/docs/cd/B28359_01/java.111/b31225/chone.htm#BABDECCF

No comments: