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
  1. Set set = new TreeSet();

  2. Set set = new HashSet();

  3. Set set = new SortedSet();

  4. List set = new SortedList();

  5. Set set = new LinkedHashSet();

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

TreeSet guarantees sorted order and uses natural ordering for Integers, so it will output [1, 2]. HashSet does not guarantee order. SortedSet is an interface, not a class, and cannot be instantiated. SortedList does not exist. LinkedHashSet maintains insertion order, not sorted order.

Multiple choice technology
  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 runtime.

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

Variable f is declared inside the try block (line 13), so it's not in scope when accessed in the finally block (line 17). Variables in try-catch-finally must be declared outside the try block to be accessible in finally.

Multiple choice technology
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes and prints "running".

  4. The code executes and prints "runningrunning".

  5. The code executes and prints "runningrunningrunning".

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

t.run() calls the method directly in the main thread (twice), printing 'running' each time. t.start() creates a new thread that also prints 'running'. Total: 3 'running' prints concatenated as 'runningrunningrunning'.

Multiple choice technology
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes and prints "StartedComplete"

  4. The code executes and prints "StartedComplete0123".

  5. The code executes and prints "Started0123Complete".

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

t.start() begins the thread, 'Started' prints, t.join() waits for thread completion (printing 0123), then 'Complete' prints. The join() ensures the main thread waits for t to finish before proceeding.

Multiple choice technology
  1. harrier

  2. shepherd

  3. retriever

  4. Compilation fails

  5. retriever harrier

  6. An exception is thrown at runtime

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

The syntax 'case default:' is invalid. In switch statements, the default case is written as 'default:' without the 'case' keyword. This causes a compilation error.

Multiple choice technology
  1. A, B, C,

  2. B, C, A,

  3. Compilation fails.

  4. The code runs with no output

  5. An exception is thrown at runtime.

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

LinkedList maintains insertion order. Elements B, C, A are added in that order, so iteration returns 'B, C, A, '. The for-each loop iterates in the order elements were inserted.

Multiple choice technology
  1. end

  2. compilation fails

  3. exception end

  4. exception test end

  5. A Throwable is thrown by main.

  6. An Exception is thrown by main.

Reveal answer Fill a bubble to check yourself
F Correct answer
Multiple choice technology
  1. compilation fails

  2. pi is bigger than 3

  3. An Exception occurs at runtime

  4. pi is bigger than 3. Have a nice day

  5. pi is not bigger than 3. Have a nice day

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

The finally keyword can only be used with a try block. Here, finally is attached to an if-else statement, which is invalid syntax. A finally block must follow a try or try-catch construct, not conditional statements.

Multiple choice technology
  1. 0

  2. 1

  3. 4

  4. Compilation fails

  5. An Exception thrown at runtime

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

If the string literal is "\s" (single backslash), this is invalid because \s is not a recognized escape sequence in Java. String escape sequences like \n, \t, \" must be valid. To represent a regex backslash, you need "\\s" (double backslash in source = single backslash in string).

Multiple choice technology
  1. int Long

  2. Short Long

  3. Compilation fails

  4. An Exception thrown at runtime

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

For go(y) with primitive short, Java prefers widening primitive conversion (short -> int) over autoboxing to Short. So go(int) is called. For go(z) with primitive long, only go(Long) matches via autoboxing (long cannot widen to int). Output is "int Long".

Multiple choice technology
  1. Hello

  2. Hello World

  3. Compilation fails

  4. Hello World 5

  5. The code runs with no output.

  6. An exception is thrown at runtime

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

Line 19 attempts to call another constructor using 'Hello()' but this is invalid syntax. In Java, to chain constructors you must use 'this(...)' or 'super(...)' as the first statement. The statement 'Hello();' looks like a method call but there's no method named Hello(), so this code will not compile. Even if it were correct constructor chaining, line 14 would throw NullPointerException because title is null when += is attempted.