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

  2. false false

  3. true false

  4. true true

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

new StringBuilder() creates two distinct objects, so == returns false (different references). StringBuilder does NOT override equals() - it inherits Object's default implementation which also checks reference equality. Therefore equals() returns false too, unlike String which compares content.

Multiple choice technology programming languages
  1. false true

  2. false false

  3. true true

  4. true false

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

After s2 = s1, both variables reference the exact same StringBuilder object. The == operator returns true (same reference). StringBuilder's equals() method (inherited from Object) also returns true because it compares references, which are now identical.

Multiple choice technology programming languages
  1. default

  2. default, zero, one

  3. Compiler error

  4. No output displayed

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

The switch expression evaluates to i = 3. Since no case matches 3, the execution jumps to the default label. Because there is no break statement after the default, case 0, and case 1 statements, execution falls through all of them until a break is encountered in case 1, printing 'default', 'zero', and 'one'.

Multiple choice technology web technology
  1. -2^15 to 2^15-1

  2. -2^7 to 2^7-1

  3. -2^31 to 2^31-1

  4. 0 to 2^16-1

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

Java's char primitive type is a 16-bit unsigned integer representing UTF-16 code units, ranging from 0 (null character) to 65535 (2^16-1). Unlike other integral types (byte, short, int), char is unsigned and cannot represent negative values. Option A describes short, B describes byte, and C describes int.

Multiple choice technology programming languages
  1. compiler error

  2. smaller type is promoted

  3. must explicitly cast

  4. none of the above

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

Java automatically promotes the smaller primitive type to match the larger type during comparison operations. This is part of binary numeric promotion - for example, an int compared to a long is promoted to long, a float compared to a double is promoted to double. This promotion happens automatically without requiring explicit casting from the programmer.

Multiple choice technology programming languages
  1. s = tcs In finally

  2. Compiler Error

  3. Exception

  4. s = tcs

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

The trimString() method calls x.trim() which removes leading/trailing whitespace. On input ' tcs ', this returns 'tcs'. The finally block always executes, so output is 's = tcs' followed by 'In finally'. No exception occurs, so flow is normal.

Multiple choice technology programming languages
  1. s = tcs Exception

  2. s = tcs Null Pointer Exception

  3. Exception

  4. Compiler Error

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

This code produces a compiler error because the catch block order is invalid. Exception is a superclass of NullPointerException, so catching Exception first makes the NullPointerException catch unreachable. More specific exceptions must be caught before their parent types.

Multiple choice technology programming languages
  1. p = 2.0

  2. Compiler Error

  3. Exception

  4. p = 2.0 In finally

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

The division 10 / 5 returns 2.0 (as double). Since no exception occurs, the catch block is bypassed. However, the finally block is guaranteed to execute regardless of whether an exception is thrown, appending 'In finally' to the output. Thus, the program prints both lines sequentially.

Multiple choice technology programming languages
  1. Compiler Error

  2. Exception happened / by zero

  3. Exception happened / by zero In finally

  4. In finally

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

The code divides 10 by 0, throwing ArithmeticException '/ by zero'. This is caught by the Exception handler, which prints the message and calls System.exit(0). System.exit() terminates the JVM immediately, so the finally block never executes. Output is only the exception message.

Multiple choice technology programming languages
  1. Exception happened / by zero In finally

  2. Exception happened / by zero

  3. In finally

  4. Compiler Error

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

Division by zero throws ArithmeticException with message '/ by zero'. The catch block prints 'Exception happened / by zero'. Control then proceeds to the finally block, which prints 'In finally'. Both statements execute in sequence.

Multiple choice technology programming languages
  1. Executing...

  2. Please Execute Me Executing... Executed

  3. Error at line 6

  4. Error Semicolon missing

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

The code has empty statements (multiple semicolons) and string literals without statements. String literals not followed by anything are valid expressions that do nothing. Line 6 and 8 are valid no-op expressions. Line 7 printf executes, printing 'Executing...'. No errors occur.

Multiple choice technology programming languages
  1. 1 1.000000

  2. 1 1.500000

  3. 0 1.000000

  4. 1 0.000000

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

Both 6/4 expressions use integer division. In C, int/int truncates toward zero. 6/4 = 1 (integer). The printf uses %d for first (prints 1) and %f for second. %f expects a float/double but receives int 1, causing undefined behavior. The expected output shows 1 and 0.000000 for this UB.

Multiple choice technology programming languages
  1. Let me work

  2. Let me workThis is case 1This is case 2

  3. Compilation Error

  4. Run Time Error

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

In C, the switch statement requires an expression of integer type (int, char, enum). A float variable cannot be used as the switch expression because float values are not discrete and cannot be compared exactly for equality matching. This code will fail to compile with an error about illegal switch expression type. Options A and B would be outputs if the code compiled, but compilation never succeeds.