03 First Class
03 First Class
¤ Currency
¤ Currency (String)
¨ Heap
¤ Holds objects created in the program
¨ Stack
¤ Used during the execution of the program
¤ Stack holds
n short lived objects (local primitive types)
n When a function is called a block of memory (stack
frame) is allocated to hold the local variables. It is
removed when the execution of function finishes
n references to other objects in the heap
¨ Object type
myString
¤ String myString;
¨ Object type
myString
¤ String myString;
1234
¤ myString = new String(“Text”);
¨ Object type
myString
¤ String myString;
1234
¤ myString = new String(“Text”);
¨ Object type
¤ String myString;
myString
¤ myString = new String(“Text”);
account1ID
1
¨ Primitive types are stored in Stack
account1Balance
1000
Ozyegin University - CS 102 - Object Oriented Programming
Bank Account
21
account1Currency
account1ID account2ID
1 2
account1Balance account2Balance
1000 800
account1Currency account2Currency
“TL” “US”
Ozyegin University - CS 102 - Object Oriented Programming
Bank Account
23
account1Balance account2Balance
¨ Before
1000 800
account1Balance account2Balance
¨ After
1050 1100
Account.java
AccountTest.java
Account.java
This is the class which
provides the specifics
of the Account object
AccountTest.java
In here, we have
two Account
objects: account1
and account2
account1 account2
account1 account2
number number
1 2
balance balance
100 200
currency currency
account1 account2
number number
1 2
balance balance
100 200
currency currency
“TL”
Ozyegin University - CS 102 - Object Oriented Programming “USD”
Printing Class Variables
36
number number
1 2
balance balance
100 200
currency currency
“TL”
Ozyegin University - CS 102 - Object Oriented Programming “USD”
Change in memory…
40
number number
1 2
balance balance
150 500
currency currency
“TL”
Ozyegin University - CS 102 - Object Oriented Programming “USD”
Object Functionality
41
number number
1 2
balance balance
100 200
currency currency
“TL”
Ozyegin University - CS 102 - Object Oriented Programming “USD”
Change in memory… (same as before)
46
number number
1 2
balance balance
150 500
currency currency
“TL”
Ozyegin University - CS 102 - Object Oriented Programming “USD”
Class
47
member variables or
instance variables
member
functions
member variables or
attributes
instance variables
behaviors member
functions