Try to print string with null in output in java





It’s a very simple program asked in interviews.

What will be output when Try to print string with null in output in java ?

public class PrintStringWithNull {
    public static void main(String[] args) {
          System.out.println("a"null);
          System.out.println(null"a");
    }
}

This program might look confusing at first look and looks like will end end up in NullPointerException, but it won’t.

//output
anull
nulla


Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.

Related >

Super keyword in java - Invoke constructor, Access instance variable, Invoke instance method of immediate super class using super


Interface in java - Multiple inheritance, Marker interfaces, When to use interface practically, 12 features

Abstract class and abstract methods in java - When to use abstract class or interface practically, 10 features


eEdit
Must read for you :