null pointer exception example

Example 1: null pointer exception

NullPointerExceptions are exceptions that occur when you try to 
use a reference that points to no location in memory (null)
 as though it were referencing an object.

Example 2: null pointer exception method

public class MainClass {

    public static void main(String[] args) {
        anotherTest();
        test();
    }
    public static void test() {
        System.out.println("Printed from the test method.");
    }
    public static void anotherTest() {
        System.out.println("Printed from the anotherTest method.");
    }
}