Output of Java programs | Set 29 Last Updated : 31 Aug, 2017 Comments Improve Suggest changes Like Article Like Report Question 1. What is the output of the following question? JAVA class Test1 { public static void main(String[] args) { int String = 65; int Runnable = 97; System.out.print(String + " : " + Runnable); } } Option A) Error B) A : a C) 65 : 97 D) 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? JAVA class Test2 { public static void main(String[] args) { int if = 65; int else = 97; System.out.println(if + " : " + else); } } Option A) Error B) A : B C) 65 : 97 D) None Output: A Explanation : We can't use reserved words as identifiers. Question 3. What is the output of the following question? JAVA class Test3 { public static void main(String[] args) { int x = 1; if (x) { System.out.print("GeeksForGeeks"); } else { System.out.print("GFG"); } } } Option A) GeeksForGeeks B) GFG C) Error D) 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? JAVA 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); } } Option A) Error B) 123.456 12_3.4_5_6 12_3.4_56 C) 123.456 123.456 123.456 D) 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? JAVA 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); } } Option A) Error B) 123.456 12_3.4_5_6 12_3.4_56 C) 123.456 123.456 123.456 D) 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. Comment More infoAdvertise with us Next Article Output of Java programs | Set 29 S Shivakant Jaiswal Improve Article Tags : Java Java-Output Practice Tags : Java Similar Reads Output of Java Program | Set 9 Difficulty level : Intermediate Predict the output of following Java Programs. Program 1: Java class Gfg { // constructor Gfg() { System.out.println("Geeksforgeeks"); } static Gfg a = new Gfg(); //line 8 public static void main(String args[]) { Gfg b; //line 12 b = new Gfg(); } } Output: G 3 min read Output of Java program | Set 27 Ques1. What is the output of the following? Java import java.util.*; public class Test { public static void main(String[] args) { int[] x = new int[3]; System.out.println("x[0] is " + x[0]); } } Options : A. The program has a compile error because the size of the array wasn't specified whe 3 min read Output of Java Programs | Set 30 QUE.1 What is the output of this program ? JAVA public class Prg { public static void main(String args[]) { System.out.print('A' + 'B'); } } OPTION a) AB b) 195 c) 131 d) Error Answer: c Explanation: Here, âAâ and âBâ are not strings they are characters. âAâ and âBâ will not concatenate. The ASCII o 2 min read Output of Java program | Set 5 Predict the output of following Java Programs.Program 1: Java // Main.java public class Main { public static void gfg(String s) { System.out.println("String"); } public static void gfg(Object o) { System.out.println("Object"); } public static void main(String args[]) { gfg(null); 3 min read Output of Java Programs | Set 31 Prerequisite : Arrays in Java 1. What will be the output of the following program? Java public class Test { public static void main(String[] args) { int[] arr = { 1, 2, 3, 4, 5 }; System.out.println(arr); } } Options: 1. 1 2. Compile-time error 3. 1 2 3 4 5 4. [I@Hashcode_in_Hexadecimal Output: The 3 min read Output of Java Program | Set 3 Predict the output of the following Java Programs: Example1: Java // filename: Test.java class Test { // Declaring and initializing integer variable int x = 10; // Main driver method public static void main(String[] args) { // Creating an object of class inside main() Test t = new Test(); // Printin 3 min read Output of Java Program | Set 7 Difficulty level : Intermediate Predict the output of following Java Programs. Program 1 : Java public class Calculator { int num = 100; public void calc(int num) { this.num = num * 10; } public void printNum() { System.out.println(num); } public static void main(String[] args) { Calculator obj = ne 4 min read Output of Java Program | Set 6 Difficulty Level: IntermediatePredict the Output of the Following Java Programs.Program 1: Constructor ChainingJavaclass First { public First() { System.out.println("a"); } } class Second extends First { public Second() { System.out.println("b"); } } class Third extends Second { public Third() { Sys 2 min read Output of Java Programs | Set 38 (Arrays) Prerequisite : Arrays in Java Question 1. What is the output of this question JAVA class Test1 { public static void main(String[] args) { int arr[] = { 11, 22, 33 }; System.out.print(arr[-2]); } } Option A) 11 33 B) Error C) exception D) 11 -33 Output: C Explanation : We will get java.lang.ArrayInde 3 min read Output of Java Programs | Set 47 (Arrays) Prerequisite : Arrays in Java Question 1. What is the output of this question? JAVA class Test1 { public static void main(String[] args) { int arr[] = { 11, 22, 33 }; for (int i = 0; i < arr.length; i++) System.out.print(arr[i] + " "); System.out.println(); int arr2[] = new int[3]; arr2 2 min read Like