X hits on this document

98 views

0 shares

0 downloads

0 comments

42 / 46

© S. Uchitel, 2004

42

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.

Document info
Document views98
Page views98
Page last viewedSun Dec 04 04:43:45 UTC 2016
Pages46
Paragraphs816
Words2901

Comments