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 programming languages
  1. Runtime Exception

  2. Compilation error at line 1

  3. 2

  4. Compilation error at line 2

  5. Compilation error at line 3

  6. Compilation error at line 4

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

The code has a compilation error because 'void' is misspelled as 'voi' in the method signature. Additionally, the syntax 'ArrayList;' is incorrect, and List is an abstract interface that cannot be instantiated directly with 'new List()'. The compilation fails at line 1 due to the typo in the method declaration.

Multiple choice technology programming languages
  1. 1}

  2. It will give error

  3. 10

  4. -10

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

X is defined as PIC 99 (2-digit integer). When SUBTRACT 20 FROM X executes, X starts at 10, and 10 - 20 = -10. Since PIC 99 cannot hold negative values, COBOL truncates/ignores the sign, resulting in 10. No error occurs - this is how COBOL handles overflow in unsigned fields.

Multiple choice technology programming languages
  1. Compilation error, attempting to perform binary comparison on logical data type.

  2. Compilation and output of "We are equal 10".

  3. Compilation and output of "Not equal! 20".

  4. Compilation and output of "Not equal! 10".

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

The code uses short-circuit AND (&&). Since b1 is false, (b1 == true) evaluates to false, so the right side ((Output += 10) == 20) is never executed due to short-circuiting. Output remains 10, the if condition is false, and the else branch prints "Not equal! 10". Option A is wrong because you can compare booleans with ==. Option C is wrong because Output is never incremented to 20.

Multiple choice technology programming languages
  1. prints: Value is - 9

  2. prints: Value is - 5

  3. Compilation error

  4. None of these

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

In Java's ternary operator, if the second and third operands have different numeric types, binary numeric promotion applies. Here, the expression's overall type is promoted to double, converting 9 to 9.0, resulting in Value is - 9.0. None of the specific print distractors matches.

Multiple choice technology programming languages
  1. 0122

  2. 0123

  3. Compilation error

  4. None of these

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

The variable i is declared within the for-loop initialization (int i = 0), so its scope is limited to the loop block. The statement System.out.print(i) outside the loop cannot access i because it's out of scope, causing a compilation error. Option B would be correct if i were declared before the loop.

Multiple choice technology programming languages
  1. Compilation Error

  2. Prints : Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes and so on.

  3. Prints : No No No No No No No No No No and so on.

  4. Prints : Yes No Yes No Yes No Yes No Yes No and so on.

  5. The Output cannot be determined.

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

Because a new thread is spawned to modify the shared variable without synchronization, there is a race condition between the main loop printing the variable and the child thread writing to it. The output depends on JVM thread scheduling and is therefore unpredictable.

Multiple choice technology programming languages
  1. Same Equals

  2. Equals

  3. Same

  4. The code compiles, but nothing is displayed upon execution.

  5. The code fails to compile.

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

The == operator compares object references, not content. s1 and s2 are different objects (created with new String()), so s1 == s2 is false. The equals() method compares String content, so s1.equals(s2) is true. Only "Equals" is printed. Option A would require both references to point to the same object.

Multiple choice technology programming languages
  1. The program will not stop and it will run recursively upon execution

  2. The program will output '0 2 5 5'.

  3. The program will output '0 2 4 4'.

  4. The program will output '02 4 5'.

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

Tracing the loop: i=0 prints "0", ++i makes i=1, break exits switch, loop increments i to 2. i=2 prints "2", i++ makes i=3, falls through to case 4 (no break), prints "4", break exits switch. Loop increments i=4 to 5. i=5 doesn't match any case, nothing prints. Loop increments i=5 to 6, loop condition i<5 fails. Output: "0 2 4 4".

Multiple choice technology programming languages
  1. The program will output 'scjp5_0.chap07.Ques01 1'.

  2. The program will output 1.

  3. The program will output '1' and then will raise an ArrayIndexOutOfBoundsException.

  4. The program won't print anything but will raise an ArrayIndexOutOfBoundsException at run-time.

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

The program is run with one command-line argument: "1". args[0] is "1", args[1] does not exist. First iteration (i=0) prints args[0] which is "1". Second iteration (i=1) tries to print args[1], which throws ArrayIndexOutOfBoundsException. The catch block silently ignores it. The loop ends. Only "1" is printed. Option C is wrong because the exception is caught.

Multiple choice technology programming languages
  1. Compilation fails due to error at line 1.

  2. Compilation fails due to error at line 2.

  3. Compilation fails due to error at line 4.

  4. Compilation fails due to error at both line 1 and line 4.

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

The varargs parameter (Integer ... i) must be the last parameter in the method signature. Line 1 has String s after Integer ... i, which is invalid varargs syntax. This causes compilation error at line 1. Line 2 (enhanced for loop) and line 4 (varargs in main method) are both valid Java syntax.

Multiple choice technology web technology
  1. True

  2. False

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

The Struts Action class uses the Adapter pattern by providing a common interface (execute() method) that adapts application-specific logic to the framework's expected contract. Different Action implementations 'adapt' their specific processing to the standard Action interface.

Multiple choice technology programming languages
  1. Hello World!

  2. "Hello World!"

  3. Compilation Fails

  4. Runtime Exception

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

The code has a critical error: main is not declared static, so it's an instance method. Java requires public static void main(String[]) as the entry point. Since main() is not static, attempting to call it causes a runtime exception (NoSuchMethodException or similar). This tests understanding of Java's main method signature requirements.