© S. Uchitel, 2004
What is null ?
Null is a value that reference types can store
E.g. Car myCar = null;
Means that myCar does not point to any object!
myCar is a null pointer
Draw the stack and heap for:
int a = 10;
Car c = null;
c = new Car(“Red”, “Fiesta”, 40);
c = new Car(“Blue”, “Torino”, 55);
Car d = c;
c = null;
d = c;
What happens if we now call: d.start();
A runtime error occurs: NullPointerException
Which means we have tried to call a method on a
reference variable that does not point to an object.