2.6. Instance Members

Each object created will have its own copies of the fields defined in its class.

Instance variables: The fields of an object are called instance variables. Also a state of the object is the values contained in the instance variables.

Instance methods: The methods of an object are called instance methods. It also defines Object’s behavior.

			package javatutorial;

			/**
			 * Example demonstrating instance members
			 * 
			 * @author f5java.com
			 */
			public class InstanceMembers {


				public static void main(String[] args) {
					
					Student student1 = new Student("Tom", "Java programming course", "A");
					Student student2 = new Student ("Harry","Fine Arts", "A");
					
					student1.displayStudentDetails(); // 1. Displays student1 details
					student2.displayStudentDetails(); // 2. Displays student2 details
					
					// Shows the instance variables and instance methods belong to objects.
					// i.e. what is displayed depends on the values set by student1 or student2 object

				}

			}