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. 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 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.

Multiple choice technology programming languages
  1. true

  2. false

  3. compilation fails at line 21

  4. compilation fails at line 22

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

Integer values between -128 and 127 are cached by Java's Integer class, so i1 == i2 returns true for small values like 100 (same object reference). For values like 1000, outside the cached range, new Integer objects are created, so i1 and i2 reference different objects, making == return false. This tests understanding of Integer caching and reference vs value comparison.

Multiple choice technology programming languages
  1. NullPointerException

  2. Compilation fails

  3. 0

  4. 1

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

args is the command-line arguments array. When running 'java A' with no arguments, args is an empty array (length 0), not null. The code correctly accesses args.length without null checks. This tests understanding that args.length is 0 for no arguments, and that an empty array is not null.

Multiple choice technology programming languages
  1. -345678-

  2. -3--4--5--6--7--8-

  3. -3--34--345--3456--34567--345678-

  4. -345678--345678--345678--345678--345678--345678--345678-

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

The regular expression \d+ matches one or more consecutive digits. The input string '345678' consists entirely of digits, so m.find() matches the entire string as a single group. The loop runs once, printing '-345678-'.

Multiple choice technology programming languages
  1. Hello---Hello

  2. Hello---HelloWorld

  3. HelloWorld---Hello

  4. HelloWorld---HelloWorld

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

String objects are immutable in Java. The concat() method returns a new String object but does not modify the original. Since s1.concat() is not assigned to any variable, s1 still points to Hello, and s2 also points to Hello.

Multiple choice technology programming languages
  1. Varargs

  2. Normal

  3. Compilation Fails

  4. Runtime Exception

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

In Java, compiler resolution favors specific parameter matching over variable arity (varargs) methods. Since add(int, int) is an exact match for the arguments (9, 9), it is chosen over the varargs option, resulting in the output 'Normal'.

Multiple choice technology web technology
  1. Infinity

  2. NaN

  3. number

  4. null

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

The expression typeof 1/0 is parsed as (typeof 1) / 0 due to operator precedence. The typeof operator returns the string "number" for the value 1. Then JavaScript attempts to divide this string by 0, which coerces "number" to NaN (since it's not a valid numeric string). Finally, NaN / 0 evaluates to NaN. This is different from simply evaluating 1/0, which would give Infinity.

Multiple choice technology
  1. Something

  2. 1

  3. Error

  4. No output

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

The break statement immediately exits the while loop before Write-Host executes. The condition ($a -eq 1) is never true because $a is a string 'something', not the integer 1, so continue is never reached. The break executes on the first iteration, terminating the loop without any output.