{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter3_2-ObjectsAndInstanceAtributes

Chapter3_2-ObjectsAndInstanceAtributes - Chapter 3...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Objects and Instance attributes and variables Chapter 3: Introduction to Classes and Objects
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 2 Objectives Object state and instance attributes Objects and Instance variables Primitive types and reference type Practical Organization
Image of page 2
Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 3 The Anatomy of an Object An object has: reference (also called Object Identifier (OID)) A unique identifier provided by the Object System and that makes the object unique. It is acquired at birth and does not change during the life of the object. State Represents the data that the object contains. Behavior Represents the services (the methods) that the object may perform. The features of an object are its attributes and operations. an instance attribute is an element of the object state . an operation is an element of the object behavior .
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 4 All objects of the same class have the same characteristics (attributes) and the same behavior (methods). Each object has a value for each instance attribute . The state of an object encompasses: all of the instance attributes of the object the current data values assigned to these attributes. When we talk about the current state of the object, we are really talking about the current values of its attributes. The values of instance attributes can change over time . A complete set of the specific values of these attributes forms a specific state of the object . Object State Object: Course studentName courseCode Mohammed CSC 112
Image of page 4
Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 5 State vs. Attribute An instance attribute is an element of the object state . The state of an object is defined by the set of values held by all its attributes . Class attributes do not belong to the object state . The characteristics (set of attributes) of an object almost never change during the object’s life. The data values of the instance attributes change. ) The attribute set is (usually) a static concept. ) While state is (usually) a dynamic concept.
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 6 Object Creation Step 1 : First declare a variable of the given class. This variable is called instance variable or object reference variable. ClassName variableName ; Step 2: Next, create the object that you refer to. The syntax for instantiating an object is: new ClassName(); Step 3: Finally, initialize the instance variable declared in 1 by assigning the newly created object to the instance variable. Just as with variable assignment or initialization. The syntax for initializing an object to an instance variable is:
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}