String x = (String) null;

Why there is no exception in this statement?

String x = null;
System.out.println(x);

It prints null. But .toString() method should throw a null pointer exception.

10 Answers
10

Leave a Reply

Your email address will not be published. Required fields are marked *