Was looking through the LinkedList java class from my computer science class and I was wondering if declaring private Node head; is the same thing as private Node head = null;?
Asked
Active
Viewed 284 times
0
Keshav Chawla
- 13
- 1
- 4
1 Answers
0
From the Java spec:
4.12.5. Initial Values of Variables
Every variable in a program must have a value before its value is used:
Each class variable, instance variable, or array component is initialized with a default value when it is created (§15.9, §15.10.2):
[...]
For all reference types (§4.3), the default value is
null.
Since the default value of all objects is null, there is no difference.