Part 12
Part 12
In Java, null is a reserved word for literal values. It seems like a keyword, but actually, it is a literal
similar to true and false.
Points to remember
o It is case-sensi ve.
o It is not allowed to pass null as a value to call the methods that contain any primi ve data
type.
AD
Example 1
Let's see a simple example to display the default value of the reference variable.
4.
5. System.out.println(obj);
6. }
7.
8. }
Output:
null
Example 2
Let's see an example to determine whether we can pass null to object reference variable.
2.
5. System.out.println(obj);
6. }
7.
8. }
Output:
null
Example 3
2.
3. String str;
6. System.out.println(obj.str);
7. }
8.
9. }
10. </pre></div>
11. <p><strong>Output:</strong></p>
13. null
14. </pre></div>
20. {
22. }
25. System.out.println(obj.display());
26. }
27. }
Output:
null
AD
Example 5
4. if(str==null)
5. {
6. System.out.println("value is null");
7. }
8. else
9. {
11. }
12. }
13. }
Output:
value is null