0

can Reference be NULL or NOt?

if reference can't be null..then Application obj; Application is a class... how the value of obj is NULL???

1st Feb 2017, 6:56 AM
Somnath Ghosh
Somnath Ghosh - avatar
6 odpowiedzi
+ 4
In your example obj is a reference with type Application. You didn't assign an object to it so its value is null by default. It means that this reference is empty.
6th Feb 2017, 7:53 PM
Tamás Barta
Tamás Barta - avatar
+ 4
Wait! What I write is true in Java (you added Java tag too) but a reference cannot be null in C++ but it is possible to reference to an invalid object.
12th Feb 2017, 5:45 PM
Tamás Barta
Tamás Barta - avatar
+ 3
Yes.
12th Feb 2017, 5:31 PM
Tamás Barta
Tamás Barta - avatar
+ 3
Not right. Can you write a simple test app in Java? Try this in Code Playground: public class Program { public static void main(String[] args) { String s = null; System.out.println(s); } }
12th Feb 2017, 5:41 PM
Tamás Barta
Tamás Barta - avatar
0
so...reference can be null??
12th Feb 2017, 5:12 PM
Somnath Ghosh
Somnath Ghosh - avatar
0
but i have attended an interview..he told difference between pointer and reference is pointer can be null but reference can not be null
12th Feb 2017, 5:38 PM
Somnath Ghosh
Somnath Ghosh - avatar