This preview shows page 1. Sign up to view the full content.
Unformatted text preview: of an object), such as
variables declared inside of a method. Page 10 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP How Objects, Primitive and Instance
Variables are Stored in Memory
• Primitive variables are stored in the stack
memory. • Instance variables are stored in stack memory. • Objects are stored in heap memory. • The myShirt and yourShirt
instance variables are referring
to different Shirt objects.
Page 11 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Assigning Objects’ References
to the same Instance Variable
Course crs; B
B A. The variable is
A. The variable is
A. allocated in memory.
allocated in memory. crs = new Course ( ); B. The reference to the
B. The reference to the
B. new object is assigned
new object is assigned
crs. crs = new Course ( ); C. The reference to
C. The reference to
Page 12 another object overwrites
another object overwrites
the reference in crs.
the reference in crs. State of Memory
Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Assigning an Object Reference
From One Variable to Another...
View Full Document
This document was uploaded on 03/03/2014.
- Spring '14