Example: NullPointerException

Single Choice
Views 35

Answer:


public class UncheckedExample2 {
    public static void main(String[] args) {
        try {
            String name = null;
            System.out.println(name.length()); // null object access
        } catch (NullPointerException e) {
            System.out.println("Object is null!");
        }
    }
}

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.