Tuesday, June 6, 2017

What is null? Is null an object?

What is null?

1. null is a type and a value. But we don't know the value. It will be anywhere. It can be replaced by other value.
2. null is often used in programs as a marker to indicate that some object is unavailable.
3. special null literal that can be used as a value for any reference type
4. null may be assigned to any variable, except variables of primitive types( 8 types: boolean , byte , char , short , int , long , float and double).

 Is null an object?

1. If null is an object, then the nullpointer exception was not occur.
2. If null were an Object, it would support the methods of java.lang.Object such as equals(). But it never do that. It gives null pointer exception.
3. null instanceof Object returns always false.

Resource Link: Is null an object? 

According to the Java spec, null is a type that can be assigned to an object variable (as a value as noted in the comment). You cannot instantiate or create variables of this type though, you must use the literal null provided by the compiler. No, it's not an instance of a Class nor a Class.

No comments:

Post a Comment