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. I am in a

  2. I am in default

  3. Exception

  4. Compiler Error

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

The switch expression is char a with value 'a'. The code has a default case first followed by case 'a'. Since the value 'a' matches case 'a' exactly, Java executes that case and prints "I am in a", then breaks out of the switch statement.

Multiple choice technology programming languages
  1. x = 42

  2. x = 43

  3. x = 44

  4. Compilation fails.

  5. The code runs with no output

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

Variable x is declared inside the try block (scope limited to try), but the finally block attempts to access and increment it with ++x. This is a compilation error because x is not in scope in the finally block. The code does not compile regardless of the exception handling.

Multiple choice technology programming languages
  1. many

  2. a few

  3. Compilation fails

  4. The output is not predictable

  5. An exception is thrown at runtime

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

Compilation fails because 7 is an integer literal of type int. Java does not allow implicit narrowing conversions (from int to short) during method invocation resolution. Since there is no invade(int) or invade(int...) method, the compiler cannot find a matching method signature for invade(7).

Multiple choice technology programming languages
  1. 2

  2. 4

  3. An exception is thrown at runtime

  4. Compilation fails due to an error on line 4

  5. Compilation fails due to an error on line 5

  6. Compilation fails due to an error on line 6

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

Line 7 casts o1 (which is a 2D int array) to a 1D int array. At runtime, this fails because o1 actually references int[][], not int[]. The cast compiles but throws ClassCastException at runtime. Line 4 compiles correctly because a[1] is a 1D array being cast to int[].

Multiple choice technology programming languages
  1. 1 1

  2. 2 1

  3. 3 1

  4. 4 1

  5. 3 3

  6. 4 3

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

The call doX(s,s) passes short values. Java's most specific matching overload is doX(Integer, Integer) because short widens to int, then autoboxes to Integer (Java 5 feature). The call doX(7,7) passes int literals which autobox to Integer, matching the same overload. Output is "3 1" - wait, 7 as int matches Integer exactly, not Long.

Multiple choice technology programming languages
  1. Line 4

  2. Line 5

  3. Line 6

  4. Line 7

  5. Line 8

  6. Line 9

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

Java 5 introduced autoboxing. Line 4: Long.valueOf returns Long but assigns to long - unboxing works in Java 5, not 1.4. Line 5: Long to Long assignment works in both. Line 7: longValue() returns long but assigns to Long - boxing works in Java 5, not 1.4. Line 8: parseLong returns long, assigning to Long requires boxing in Java 5 only.

Multiple choice technology programming languages
  1. Only one compilation will succeed.

  2. Exactly two compilations will succeed.

  3. Exactly three compilations will succeed.

  4. All four compilations will succeed.

  5. No compiler warnings will be produced.

  6. At least one compiler warning will be produced.

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

Java 1.3 allows assert as an identifier, so One.java compiles with -source 1.3. Java 1.4 made assert a keyword, so One.java fails with -source 1.4. Two.java uses assert as a keyword, so it compiles with -source 1.4 but fails with -source 1.3. Exactly two compilations succeed. Using -source 1.4 in Java 5+ produces a warning about obsolete source option.

Multiple choice technology programming languages
  1. hi

  2. hi hi

  3. hi hi hi

  4. Compilation fails

  5. hi, followed by an exception

  6. hi hi, followed by an exception

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

m2.go() prints hi because m2's m1 is null by default. m3.go() prints hi because m3's m1 is set to m2. m4.go() prints hi because m4 is same as m3's m1. When m5.go() is called, m2.m1 is null (default value), so calling go() on null throws NullPointerException after printing hi twice.

Multiple choice technology programming languages
  1. true true

  2. false true

  3. true false

  4. false false

  5. Compilation fails.

  6. An exception is thrown at runtime

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

Explanation: Let's go through the code step by step to understand the result.

  1. We have a class called "Fizz" with an instance variable "x" initialized to 5.

  2. In the main method, we create two instances of the "Fizz" class - f1 and f2.

  3. We then call the static method "FizzSwitch" passing f1 and f2 as arguments. In this method, we declare a final variable "z" and assign it the value of "x" (which is f1).

  4. Next, we modify the value of "x" using the "z" reference. Therefore, the value of "x" in f1 is changed to 6.

  5. Finally, we return the reference "z" (which is f1) and assign it to the variable "f3".

  6. In the println statement, we compare if f1 and f3 are the same object reference (f1 == f3) and if their instance variable "x" is the same (f1.x == f3.x).

Now let's analyze the options:

Option A) true true - This option is correct because f1 and f3 refer to the same object, and the value of "x" in both objects is 6.

Option B) false true - This option is incorrect because f1 and f3 refer to the same object, so f1 == f3 should be true.

Option C) true false - This option is incorrect because f1 and f3 refer to the same object, so f1 == f3 should be true.

Option D) false false - This option is incorrect because f1 and f3 refer to the same object, so f1 == f3 should be true.

Option E) Compilation fails - The code does not have any compilation errors, so this option is incorrect.

Option F) An exception is thrown at runtime - The code does not have any exceptional behavior, so this option is incorrect.

The correct answer is option A) true true. This option is correct because f1 and f3 refer to the same object, and the value of "x" in both objects is 6.

Therefore, the result of the code is "true true".

The correct answer is option A.

Multiple choice technology programming languages
  1. 343 340 340

  2. 343 340 342

  3. 343 341 342

  4. 343 341 340

  5. Compilation fails.

  6. An exception is thrown at runtime

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

Static field tooth (343) prints first. The final local tooth (340) shadows the static field. doIt receives 340, pre-increments to 341 (prints), pre-increments to 342 (returns, discarded). main's final tooth remains 340 (passed by value).

Multiple choice technology databases
  1. I am in Others Exception

  2. I am in no data found Exception

  3. Compilation Error

  4. None of the above

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

PL/SQL requires exception handlers in order: WHEN OTHERS must be last. Here, WHEN no_data_found appears after WHEN OTHERS, causing compilation error. Also, Null is not a valid executable statement.

Multiple choice technology programming languages
  1. One of them will compile, only one will be true.

  2. Two of them will compile, only one will be true.

  3. Two of them will compile, two will be true.

  4. Three of them will compile, only one will be true

  5. Three of them will compile, exactly two will be true.

  6. Three of them will compile, exactly three will be true.

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

Analyzing each fragment: F1 (f1 == f2) won't compile - comparing primitive to 2D array. F2 (f1 == f2[2][1]) compiles and compares 2.3f == 2.7f, which is false. F3 (x == f2[0][0]) compiles with unboxing, 42L == 42.0f is true. F4 (f1 == f2[1,1]) won't compile - invalid comma syntax. F5 (f3 == f2[2]) compiles but compares array references, which is false. Thus F2, F3, F5 compile (3 total), but only F3 is true (1 true).

Multiple choice technology programming languages
  1. I am in for loop

  2. Infinite Loop

  3. Compiler Error

  4. Exception

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

This code contains an infinite loop because the for loop has no initialization, condition, or increment/decrement parts - it is written as 'for(;;)' which creates an endless loop. The statement 'I am in for loop' will print continuously without termination. Options A, C, and D are incorrect because the code compiles successfully and runs indefinitely.

Multiple choice technology programming languages
  1. I am in do-while

  2. I am in while I am in do-while

  3. Compiler Error

  4. No output

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

The do-while loop executes once because the condition is checked at the end. Inside, the while loop condition p>100 is initially false (p equals 100), so it never executes. Therefore, only the do-while body prints once.

Multiple choice technology programming languages
  1. i in loop = 0 i in loop = 1 i in loop = 2

  2. i in loop = 0 i in loop = 0 i in loop = 1 i in loop = 2

  3. i in loop = 0 i in loop = 2

  4. Compiler Error

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

The loop runs for i values 0, 1, and 2. When i = 0, p = 1, printing 'i in loop = 0'. When i = 1, p = 2, triggering the continue statement and skipping the print. When i = 2, p = 3, printing 'i in loop = 2'.