Computer Knowledge

Programming Output Evaluation

1,953 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 programming languages
  1. 65536

  2. 65535

  3. 1

  4. -1

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

The byte -1 has all bits set (11111111 in two's complement). When cast to char, sign extension produces 0xFFFF (16 bits all 1), which represents 65535 in unsigned char. Cast to int preserves this value as 65535. This demonstrates sign extension behavior during primitive widening conversions.

Multiple choice technology programming languages
  1. 0.0

  2. Compilation fails

  3. A ParseException is thrown by the parse method at runtime.

  4. A NumberFormatException is thrown by the parse method at

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

Variable f is declared inside the try block, so its scope is limited to that block. The catch block attempts to assign to f, and the finally block attempts to read f, but f is not in scope in either location. This causes compilation failure due to scope violations.

Multiple choice technology programming languages
  1. 1 2 3

  2. B. Compilation fails because of an error in line 12.

  3. B. Compilation fails because of an error in line 13.

  4. B. Compilation fails because of an error in line 14.

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

An int array is assigned to an Object reference (valid upcast). The Object is then cast back to int[](valid downcast since the runtime type is int[]). The enhanced for loop iterates over the array, printing 1 2 3. The cast succeeds because the actual object type is int[].

Multiple choice technology programming languages
  1. collie

  2. harrier

  3. Compilation fails

  4. collie harrier

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

The switch statement matches the collie case and prints collie. Since there is no break statement, execution falls through to the harrier case, which also prints harrier. This fall-through behavior occurs because switch cases without break statements continue executing subsequent cases.

Multiple choice technology programming languages
  1. c

  2. a

  3. ab

  4. ac

  5. bc

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

NullPointerException is caught by the first catch block (more specific), printing a. The finally block always executes regardless of whether an exception was caught, printing c. The second catch block for RuntimeException is skipped because the exception was already caught by the more specific handler. Result is ac.

Multiple choice technology programming languages
  1. a b c

  2. 1 2 3

  3. a1b2c3

  4. Compilation fails

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

The regex \d matches each digit character. String.split() removes these digit delimiters, producing an array [a, b, c]. The enhanced for loop prints each token followed by a space, resulting in a b c. Trailing empty strings are discarded by default in Java's split method.

Multiple choice technology programming languages
  1. r, t, t,

  2. r, e, o,

  3. Compilation fails.

  4. An exception is thrown at runtime.

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

The code uses assignment operator (=) instead of equality operator (==) in the if condition on line 13. In Java, the assignment returns a value, but there's a type mismatch: check is int while str.length() returns int. However, the real issue is that you cannot assign an int value to an int variable in the condition - the expression 'check = str.length()' tries to assign, but the result is int, not boolean. Java requires boolean conditions in if statements, so this fails compilation.

Multiple choice technology programming languages
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints “bar”.

  4. The code executes normally, but nothing prints.

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

This code creates a new Thread with a Runnable that prints 'bar', then starts it. The code compiles successfully and runs normally, printing 'bar' when the thread executes its run() method. No exceptions are thrown.

Multiple choice technology programming languages
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints “sleep”.

  4. The code executes normally, but nothing is printed.

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

Thread.sleep() throws InterruptedException, a checked exception. Since main() declares 'throws Exception', it properly handles this. The code compiles, sleeps for 3 seconds, then prints 'sleep' normally.

Multiple choice technology programming languages
  1. args.count

  2. args.length

  3. args.count()

  4. args.length()

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

Command-line arguments in Java are passed as a String array named args. The length of an array is accessed via the .length property (not a method like length()). So args.length gives the number of arguments.