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 web technology
  1. Compile time error

  2. 5

  3. 0

  4. None of above

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

Local variables in Java must be initialized before use. Variable i is declared but never assigned a value before i = i + 5 attempts to read it. This violates Java's definite assignment rules, causing compile-time error.

Multiple choice technology programming languages
  1. Compile time error at line 3

  2. Compile time error at line 4

  3. 5.22

  4. None of above

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

The literal 2.12 is a double in Java. Assigning a double to float variable without cast or f suffix causes compile-time error. Should be 2.12f or (float)2.12.

Multiple choice technology programming languages
  1. Compile time error at line 3

  2. Compile time error at line 4

  3. 5

  4. None

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

Line 3 is valid: (int)2.12 casts double to int (truncates to 2), then implicit narrowing to byte works. Line 4 fails: b + 3 promotes byte to int, result is int, cannot assign int to byte without cast. b = (byte)(b + 3) would fix it.

Multiple choice technology programming languages
  1. Compile time error at line 3

  2. Compile time error at line 4

  3. 22

  4. None of above

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

Method execute expects short parameter. Literal 3 is int by default. Java does NOT implicitly narrow int to short for method calls. Must call with (short)3 or pass short variable.

Multiple choice technology programming languages
  1. -ic mc of mf

  2. Compilation fails.

  3. -ic mc mf of

  4. -ic mf of

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

In this nested try-catch structure: inner try throws Exception, caught by inner catch (s += 'ic '), then throws new Exception caught by middle catch (s += 'mc '), middle finally executes (s += 'mf '), then outer finally executes (s += 'of '). Result: '-ic mc mf of'

Multiple choice technology programming languages
  1. 8

  2. 8 7

  3. An exception is thrown at runtime.

  4. Compilation fails.

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

In Java, a labeled continue statement can only target a loop structures like for, while, or do-while. Since the label here targets an if conditional block instead of a loop, the code fails compilation with a syntax error.

Multiple choice technology programming languages
  1. It prints X and never exits.

  2. The code does not compile.

  3. It prints XY with a 10-second delay between X and Y.

  4. An exception is thrown at runtime.

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

The wait() method can only be called on an object whose monitor the current thread holds. The code calls t.wait(10000) on a Thread object without synchronizing on it first. This throws IllegalMonitorStateException at runtime. The thread starts successfully and prints X, but wait() fails.

Multiple choice technology programming languages
  1. An exception occurs at runtime.

  2. Compilation fails.

  3. 57 22

  4. 45 57

Reveal answer Fill a bubble to check yourself
D Correct answer
Multiple choice technology programming languages
  1. -A.

  2. An exception is thrown at runtime.

  3. -A

  4. A

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

Given the command line java _ - A, the arguments passed are "-" and "A". The loop initializes x to 0, but the pre-increment ++x in the condition immediately increases x to 1 before accessing __A_V_[x]. Thus, only index 1 ("A") is appended, printing "A".