Output of Java programs | Set 29 - GeeksforGeeks

31 Aug, 2017
Question 1. What is the output of the following question?
class Test1 {public    static void main(String[] args)    {        int String = 65;        int Runnable = 97;          System.out.print(String + " : " + Runnable);    }}
OptionA) ErrorB) A : aC) 65 : 97D) None
Output: C
Explanation : We can use all predefined Java class name and interface name as identifiers.
Question 2. What is the output of the following question?
class Test2 {public    static void main(String[] args)    {        int if = 65;        int else = 97;          System.out.println(if + " : " + else);    }}
OptionA) ErrorB) A : BC) 65 : 97D) None
Output: A
Explanation : We can’t use reserved words as identifiers.
Question 3. What is the output of the following question?
class Test3 {public    static void main(String[] args)    {        int x = 1;          if (x) {            System.out.print("GeeksForGeeks");        } else {            System.out.print("GFG");        }    }}
OptionA) GeeksForGeeksB) GFGC) ErrorD) None
Output: C
Explanation :In Java, Compiler gives error – Incompatible types : int can not be converted to boolean type.But in C or C++ its a valid statement.
Question 4. What is the output of the following question?
class Test4 {public    static void main(String[] args)    {        double d1 = 123.456;        double d2 = 12_3.4_5_6;        double d3 = 12_3.4_56;          System.out.println(d1);        System.out.println(d2);        System.out.println(d3);    }}
OptionA) ErrorB) 123.45612_3.4_5_612_3.4_56C) 123.456123.456123.456D) None
Output: C
Explanation : From (1.7v onwards)we can use ‘_'(under Score) Symbol between digits of numeric literals. See more at Java naming conventions.
Question 5. What is the output of the following question?
class Test5 {public    static void main(String[] args)    {        double d1 = _123 .456;        double d2 = 12_3_.4_5_6;        double d3 = 12_3.4_56_;          System.out.println(d1);        System.out.println(d2);        System.out.println(d3);    }}
OptionA) ErrorB) 123.45612_3.4_5_612_3.4_56C) 123.456123.456123.456D) None
Output: A
Explanation : We can use the ‘_’ (under score) symbol only between the digits. if we are using anywhere else we will get compile time error – Illegal under score.
This article is contributed by Shivakant Jaiswal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Java-Output
Program Output
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Output of Java program | Set 18 (Overriding)
Output of C++ programs | Set 34 (File Handling)
Different ways to copy a string in C/C++
Output of Python Program | Set 1
Output of C++ programs | Set 50
Runtime Errors
Output of C Programs | Set 2
C++ Programming Multiple Choice Questions
Output of C++ Program | Set 1
Output of Java Program | Set 20 (Inheritance)