Chapter3_2-ObjectsAndInstanceAtributes

Page 10 dr s gannouni dr a touir introduction to oop

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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 crs Course Course Course Course A A 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 to crs. tocrs crs. crs = new Course ( ); C. The reference to C. The reference to C. C C Code 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.

Ask a homework question - tutors are online