In other words:
int x; // int is a prim. type // x is a veriable of a prim. type x.methodName(...); ????
In the second part, we will learn how variable of a class are stored.
The following figure shows the content of the symbol table
after processing the variable definitions:
In the example, we assumed that:
So some portion of the memory is used, while other part are unused:
The computer first reserve a portion of memory that is sufficient to hold values of the type of the variable.
Then the computer must remember (record) the type and location information of the variable (otherwise, the computer will not be able to find the variable when it needs to use it !!!)
Example 1: what happens internally in a computer when an integer is defined.
The assignment statement "x = 4;" instructs the computer to store the value 4 into the memory location reserved for the variable x
You don't know where to store the value and cannot complete the assignment statement !!!
You don't know how many bytes to use when storing the value and can also not complete the assignment statement !!!
When the computer encounters a statement that uses a variable (here: x)
(NOTE: the example assumes that the previous example is void; i.e., there is no variable "int x;" defined previously !!!)
Very Important NOTES:
In other words: a Rectangle variable is NOT the same as a Rectangle object !!!
We will learn more about this next...