Java Programming - Objects and Collections - Discussion
Discussion Forum : Objects and Collections - Finding the output (Q.No. 2)
2.
What will be the output of the program?
public class Test
{
public static void main (String args[])
{
String str = NULL;
System.out.println(str);
}
}
Answer: Option
Explanation:
Option B is correct because to set the value of a String variable to null you must use "null" and not "NULL".
Discussion:
5 comments Page 1 of 1.
Priyank said:
5 years ago
I think it will throw NullPointerException, which means RuntimeException.
Bagsari said:
8 years ago
Compile time error everything in string enclosed within double quotes am I right.
SKumar said:
8 years ago
The null is a keyword in java and it is case sensitive. So, we can use null instead of NULL or Null.
The Following program will run successfully.
public class Test
{
public static void main (String args[])
{
String str = null;
System.out.println(str);
}
}
Output : null.
The Following program will run successfully.
public class Test
{
public static void main (String args[])
{
String str = null;
System.out.println(str);
}
}
Output : null.
Jitendra said:
1 decade ago
String str =" NULL";
NULL is not a keyword.
NULL is not a keyword.
Deep said:
1 decade ago
As per my knowledge null is not a keyword, so we can assign in any way.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers