Computer Knowledge

Programming Output Evaluation

1,721 Questions

Programming output evaluation tests the ability to trace code execution in languages like C, Java, and SAS. It focuses on arrays, loops, pointers, and data type conversions. These technical questions are standard in computer knowledge sections for IT officer and bank exams.

Java string bufferC language pointersLoop execution outputsData type conversionsMacro variable evaluation

Programming Output Evaluation Questions

Multiple choice
  1. Found 3 at 2

  2. Found 3 at 3

  3. Found 3 at 4

  4. Compilation fails

  5. Run time error

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The following line does not compile: System.out.print (found + key + at + pos). 

Multiple choice
  1. Zero

  2. Once

  3. Twice

  4. Thrice

  5. Compilation error

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is the correct choice. The for statement, for (String ss: table) is executed one time for each of the three elements in table. 

Multiple choice
  1. 4 null

  2. Null 4

  3. An exception is thrown at run time.

  4. 4 an ArrayIndexOutofbound exception is thrown.

  5. Compilation fails

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is the correct answer. The first print in statement, system.out.println(array [4][1]), works fine. It selects the element/array with index 4, {0, 4, 8, 12, 16} and from this array, it selects the element with index 1, which is 4. So, 4 gets printed. The second print in statement, system.out.println(array) [1][4]) fails. It selects the array/element with index 1,{0, 1} and from this array, it tries to select the element with index 4. This causes an exception. So, an exception in thread main java.lang.ArrayIndexOutOfBoundsException occurs.

Multiple choice
  1. 6 5 6 4

  2. 6 5 5 4

  3. 6 5 6 6

  4. Run time error

  5. Compilation fails

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Within main program, z is assigned value 6. So, z = 6 is printed first. Within doStuff, z is assigned 5. DoStuff2 locally sets z to 4 (but MyScope.z is set to 4), but in dostuff, z is still 5. So, z=5 is printed. Again z is printed within main (with local z set to 6). So, z = 6 is again printed and finally myScope.z is printed. 

Multiple choice
  1. Compilation Fails

  2. Null

  3. 0

  4. Java.lang.ArrayIndexOutOfBoundException

  5. Java.lang.NullPointerException

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

This is the correct choice because an array variable (here xx) can very well have the null value. Null is the reserved constant used in Java to represent a void reference, i.e. a pointer to nothing. Internally, it is just a binary 0, but in the high level Java language, it is a magic constant, quite distinct from zero, that internally could have any representation. So, this answer is correct.

Multiple choice
  1. 1

  2. 2

  3. Null

  4. Infinite loop

  5. Compilation Error

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

This is the correct choice because the line while (--ii); will cause the compilation to fail. --ii is not a boolean value. A correct line would be while (--ii>0); we can pass only Boolean values to the while loop. So, this is the correct choice.

Multiple choice
  1. It is a prime number.

  2. It is a palindrome.

  3. It is a prime number. It is a palindrome.

  4. Invalid value

  5. Compilation fails

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

This is the correct choice. The program contains a compilation error. The switch contains two duplicate case values (353) which is not allowed in java. 

Multiple choice
  1. Garbage value 6 5 6 4

  2. 6 6 5 6 4

  3. 0 6 5 6 4

  4. Compilation error

  5. Run time error

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct choice. Firstly, myscope.z will be printed, but it has not been initialised to any value. Initially it has a default value 0. So, 0 gets printed. Within main program, z is assigned the value 6. So, z = 6 is printed first. Within doStuff z is assigned 5. DoStuff2 locally sets z to 4 (but MyScope.z is set to 4), but in Dostuff z is still 5. So, z = 5 is printed. Again z is printed within main (with local z set to 6). Then z = 6 is again printed and finally MyScope.z is printed. MyScope.z has been set to 4 within doStuff2(). So, z = 4 gets printed. So, the correct output is 6 5 6 4. This is the correct choice.

Multiple choice
  1. Null

  2. False

  3. Java.Lang.NullPointerException

  4. 0

  5. Compilation fails

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

This is the correct choice. Line if(xx) contains an error because we can pass only Boolean value to the if() condition, but here null is passed. So, the compiler will raise an error that “cannot be converted to Boolean”. So, this answer is true.

Multiple choice
  1. Null

  2. Java.lang.NullPointerException

  3. 0

  4. Compilation fails

  5. None of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

This is the correct choice. Java.lang.NullPointerException will be thrown as we are trying to access the array that has been assigned a null value. So, exception will be thrown at run time. So, this is the correct choice.

Multiple choice
  1. Zero times

  2. Once

  3. Twice

  4. Thrice

  5. Compilation fails

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is the correct choice. The for statement, for (String ss: table), is executed one time for each of the three elements in table. The output comes out to be : aa, 0aa, 1aa, 2bb, 0bb, 1bb, 2cc, 0cc, 1cc, 2. So, “aa” will be printed 3 times, hence this answer is correct.

Multiple choice
  1. One

  2. Two

  3. Three

  4. Compilation fails

  5. Run time error

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is the correct choice. Overloading of the x method fails as the input argument in all three cases are double. To use overloading of methods, the argument types must be different. Note: The Java programming language supports overloading methods and Java can distinguish between methods with different method signatures. This means that methods within a class can have the same name if they have different parameter lists.