The NULL reference

  1. The null reference is a special reference value that means does not refer to any object

    Example:

    MyVariable does not refer to any object.

  2. How to assign null to an object variable:


    Example:
       BankAccount myVariable = null;
    
    or:
    
       BankAccount myVariable;
       myVariable = null;
    

  3. If you try to invoke a method on an object variable that contains the null reference, your program will termintae immediately


    Example: do NOT try this:
       BankAccount harrysChecking = null;
    
       harrysChecking.deposit(1000.0);