Java References
üAn reference variable holds the
memory address.
üIt is similar to the pointer.
üKey difference- cannot manipulate
as pointer– It point any arbitrary memory location
or it cannot be manipulate like an integer.
üAn object reference variable that does
not currently point
to an object is called a null
reference.
üThe reserved word null can be used to
explicitly set a null
reference:
name
= null;
üAn object reference variable declared at
the class level (an
instance variable) is automatically initialized to null
üThe programmer must carefully ensure that
an object reference
variable refers to a valid object before it is used.
Instance
variables
üDefault initialization
üIf the variable is within a method, Java
does
NOT initialize it.
üIf the variable is within a class, Java
initializes it as follows:
üNumeric instance variables
initialized to 0.
üLogical instance variables
initialized to false.
üObject instance variables
initialized to null.
No comments:
Post a Comment