String s = null;
int len = s.length();What happens at runtime?
String s = null;
int len = s.length();What happens at runtime?
Compilation fails
Runtime error: NullPointerException
Runtime error: ClassCastException
Prints 0
Prints 4
Correct answer
Runtime error: NullPointerException
Attempting to invoke an instance method on a `null` reference throws a `NullPointerException`. `String` is a reference type, and `s` is `null`, so `s.length()` triggers the exception.