- The type information of
primitive types tells the computer
which encoding schmeme it
needs to use to encode/decode information.
Example: int uses
the binary number system as code
Content value encoded
=========================================
00000000 0
00000001 1
00000010 2
00000011 3
... ...
|
- The type information of
user-defined types (= objects !) tells the computer
how to find the variables
inside the user-defined object
Example: description of
the BankAccount object
tells the Java compiler
how to
find the various variables
in a BankAccount object
Type information (= description) of a BankAccount object:
public class BankAccount
{
private int accNum; // an int variable is 4 bytes long
private String name; // a String variable is 4 bytes long
private double balance; // a double variable is 8 bytes long
}
BankAccount a = new BankAccount( .... );
The variable a contains the location of a BankAccount object:
The type information (= description) of BankAccount
tells the Java compiler that:
The variable a.accNum is located at address 5060
The variable a.name is located at address 5064
The variable a.balance is located at address 5068
|
(BTW, when the Java compiler has located
the variable a.accNum, it
also knows that a.accNum
is a primitive type variable (int)
and will use the
binary number system to
decode the value)
|