Expand|Select|Wrap|Line Numbers
- public class WhatTheShoot {
- public static void main(String args[]){
- try {
- throw null;
- } catch (Exception e){
- System.out.println(e instanceof NullPointerException);
- System.out.println(e instanceof FileNotFoundException);
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- true
- false
Why can I throw null in Java, and why does it upcast it to a NullPointerException?
I'm not sure if this is considered an "upcast" since I'm passing a null value.
I cannot think of any valid reasons to use a null value in an interview.Maybe you're hoping to get fired, but why would anyone purposely do something that would result in their dismissal? I went through this resource but didn't get it.