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 technology web technology
  1. t t1

  2. t1 t

  3. t t

  4. Compilation succeed but Runtime Exception

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

Setting thread priority to -3 throws IllegalArgumentException because Thread priority must be between MIN_PRIORITY (1) and MAX_PRIORITY (10). The code compiles successfully but fails at runtime when t1.setPriority(-3) executes. Thread priorities range from 1-10 only; values outside this range cause runtime exceptions.

Multiple choice technology web technology
  1. good

  2. Compilation succeed but Runtime Exception

  3. null

  4. Compilation fails with an error at line 5

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

The code creates a Thread with Runnable object A, names it 'good', and starts it. The run() method prints the current thread's name using Thread.currentThread().getName(), which returns 'good' since we explicitly set it with t.setName(). No compilation or runtime errors occur.

Multiple choice technology web technology
  1. false

  2. Compile Error - can't use Boolean object in if().

  3. true

  4. Compile Properly but Runtime Exception.

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

Java allows Boolean objects in if() statements due to autounboxing. The Boolean object 'expr' with value true autounboxes to primitive true, so the condition is satisfied and 'true' is printed. This is valid Java syntax - no compilation or runtime error occurs.

Multiple choice technology web technology
  1. Compile Properly but Runtime Exception

  2. Compile time error, because you have to do int total = ((Integer)(list.get(0))).intValue();

  3. 59

  4. Compile time error, because can't add primitive type in List.

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

Java autoboxes the primitive int 59 to Integer when added to the ArrayList. Then get(0) returns the Integer object, which autounboxes to int when assigned to the primitive variable 'total'. The code compiles and runs successfully, outputting 59. No explicit casting or type conversion is needed thanks to autoboxing/autounboxing.

Multiple choice technology web technology
  1. NullPointerException

  2. 0

  3. Complie with Error

  4. Null

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

When unboxing a null Integer reference to a primitive int, Java throws NullPointerException at runtime. The code compiles successfully because the assignment is syntactically valid - the error occurs during execution when the JVM tries to extract the int value from null.

Multiple choice technology programming languages
  1. 9.9

  2. 9

  3. 9.0

  4. None of the above

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

Since a = 5, the condition (a < 5) is false, so the ternary operator returns the second operand 9. However, the ternary has operands 9.9 (double) and 9 (int), so the result type is double due to numeric promotion. The integer 9 is promoted to 9.0, and the output is 'Value is - 9.0'. Option C is correct.

Multiple choice technology programming languages
  1. The code won't compile

  2. Some things are true in this world

  3. Hey this won't compile

  4. none of the above

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

The code is a nested if-else structure. 'if (a == true)' is true. Then it checks 'if (b == true)', which is false. This triggers the 'else if (a && (b = c))' on line 8. Since 'a' is true and the assignment '(b = c)' evaluates to true, it prints 'It's too confusing to tell'. Since this is not an option, 'none of the above' is correct.

Multiple choice technology programming languages
  1. 1

  2. Error anar is referenced before it is initialized.

  3. 2

  4. Error: size of array must be defined.

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

The array anar is initialized with elements {1, 2, 3}. Since Java arrays use zero-based indexing, anar[1] refers to the second element, which is 2.

Multiple choice technology programming languages
  1. System.out.println( -1 >>> 2);will output a result larger than 10

  2. System.out.println( -1 >>> 2); will output a positive number

  3. System.out.println( 2 >> 1); will output the number 1

  4. System.out.println( 1 <<< 2); will output the number 4

Reveal answer Fill a bubble to check yourself
A,B,C Correct answer
Explanation

-1 >>> 2 (unsigned right shift) produces a large positive number because -1 is all 1s in binary. The result 1073741823 is larger than 10. 2 >> 1 equals 1 (right shift halves it). <<< is not a valid Java operator.

Multiple choice technology programming languages
  1. Compiler Error

  2. Compiles and runs

  3. Runtime Error

  4. None of these

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

In Java, floating-point division by zero produces Infinity (positive or negative) rather than a runtime error. The code compiles successfully and executes without throwing an exception. Division by zero only throws ArithmeticException for integer types (int, long), not floating-point types (float, double).

Multiple choice technology programming languages
  1. '054345''

  2. '0054345''

  3. 54345'0'

  4. d'54345'00'

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

$PAD adds padding characters to the left side of a string to reach the target length. '54345' (5 characters) padded with '0' to length 6 becomes '054345', with one zero added to the left.

Multiple choice technology programming languages
  1. x[24] is 0

  2. x[24] is undefined

  3. x[25] is 0

  4. x[0] is null

  5. x.length is 25

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

When an int array is created in Java, all elements are automatically initialized to 0 by default. A 25-element array has valid indices from 0 to 24, so x[24] is the last element and contains 0. The array's length is 25, accessible via x.length. Option C is wrong because x[25] is out of bounds, option D is wrong because int arrays cannot contain null (they contain primitive int values), and option B is wrong because array elements are initialized, not undefined.

Multiple choice technology programming languages
  1. -1

  2. 0

  3. 4

  4. 8

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

To solve this question, the user needs to know what the indexOf() method does in Java. The indexOf() method returns the index of the first occurrence of a specified substring within a string, or -1 if the substring is not found.

In the given code fragment, the variable s is assigned the string "Foolish boy.", and the indexOf() method is called on this string with the argument "fool". Since the substring "fool" is not present in the original string (due to the capital letter 'F' in the string), the indexOf() method returns -1.

Therefore, the correct answer is:

The Answer is: D. -1