Output of Java program | Set 27
Ques1. What is the output of the following?
A. The program has a compile error because the size of the array wasn’t specified when declaring the array.
B. The program has a runtime error because the array elements are not initialized.
C. The program runs fine and displays x is 0.
D. The program has a runtime error because the array element x is not defined.
Answer : C
Explanation : Program is syntactically correct, so no error. In java, if the array is not initialized at the time of declaration and creation then all the elements of the array are initialized to 0 by default.
Ques2. What is the output of the following?
A. 120 200 16
B. 120 200 14
C. 120 200 016
D. 016 is a compile error. It should be written as 16.
Answer : B
Explanation : 016 is an octal number. The prefix 0 indicates that a number is in octal and in octal 16 is equal to 14.
Ques3. What is the output of the following?
A. false true
B. false false
C. true false
D. true true
Answer : D
Explanation : Both == and equals() are same things and evaluate to true/false.
Ques4. What is the output of the following?
A. S1=123456, S2=579
B. S1=123456, S2=123456
C. S1=579, S2=579
D. None of This
Answer : A
Explanation : If a number is quoted in “” then it becomes a string, not a number any more. So in S1 it is concatenated as string and in S2 as numeric values.
Ques5. What is the output of the following?
A. 1 2 3 4
B. 0 0 0 0
C. 1 2
D. 0 0
Answer : C
Explanation : The length of x array is 2. So the loop will execute from i=0 to i=1.
This article is contributed by Rishabh Jain. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.