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. Compilation and output of the value 0

  2. Compile time error because i has not been initialized

  3. Compilation and output of null

  4. Compile time error

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

Local variables cannot be declared static - only class-level fields can be static. The code 'static int i;' inside a method causes a compile-time error. Option D correctly identifies this.

Multiple choice technology programming languages
  1. short myshort = 99S;

  2. String name = 'Excellent tutorial Mr Green';

  3. char c = 17c;

  4. int z = 015;

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

Option D is correct - int z = 015 compiles because Java allows integer literals with leading zeros (interpreted as octal, 015 = 13 decimal). Options A and C are incorrect (99S and 17c are invalid suffixes). Option B is incorrect (strings require double quotes, not single).

Multiple choice technology programming languages
  1. Prints: false,false,false

  2. Prints: false,true,false

  3. Prints: true,false,true

  4. Prints: true,true,true

  5. None of the above

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

LinkedHashSet extends HashSet, which implements Set, which in turn extends Collection. Therefore, an instance of LinkedHashSet is an instance of Collection, Set, and HashSet, making all three instanceof checks evaluate to true.

Multiple choice technology programming languages
  1. Prints: false,false,false

  2. Prints: false,true,false

  3. Prints: false,true,true

  4. Prints: true,true,false

  5. Prints: true,true,true

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

ArrayList.listIterator() returns a ListIterator object. A ListIterator is NOT an instanceof List (it's an iterator over a list), but it IS an instanceof Iterator (implements that interface), and IS an instanceof ListIterator. Thus the output is 'false,true,true'. Option C matches this output.

Multiple choice technology programming languages
  1. Prints: NaN

  2. Prints: 0.0

  3. Prints: 0

  4. Compile-time error

  5. Run-time error

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

Math.round(Float.NaN) returns 0, not NaN. The round method converts the float NaN to an integer, and integer NaN is represented as 0. This is a subtle behavior of the Math.round method with NaN inputs.

Multiple choice technology programming languages
  1. Prints: 7

  2. Prints: 7.0

  3. Compile-time error

  4. Run-time error

  5. None of the above

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

Byte class does not have a charValue() method. All other methods (byteValue, shortValue, intValue, longValue, floatValue, doubleValue) exist in the Byte class, but charValue() does not exist, causing a compile-time error.

Multiple choice technology programming languages
  1. Prints: 0xFFFF,0xFFFF,false

  2. Prints: 0xFFFF,0xFFFF,true

  3. Prints: -1,-1,false

  4. Prints: -1,-1,true

  5. Compile-time error

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

Double(0xFFFF) creates a Double object with value 65535.0. When converted to byte or short, the value is -1 due to overflow. The sum of e+f+g+h equals 4*65535, so the expression evaluates to true. The output is -1,-1,true.

Multiple choice technology programming languages
  1. Prints: false,false,false

  2. Prints: false,false,true

  3. Prints: true,false,false

  4. Prints: true,false,true

  5. Prints: true,true,true

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

Boolean.valueOf(true) caches the Boolean.TRUE object, so b1==b2 returns true (same reference). The booleanValue() comparison also returns true. Boolean.valueOf is case-insensitive, so b3 and b4 are both TRUE and equals returns true. Output: true,true,true.

Multiple choice technology programming languages
  1. Prints: false,false,false

  2. Prints: false,true,false

  3. Prints: true,false,false

  4. Prints: true,true,false

  5. Prints: true,true,true

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

In Java, the expression v != v evaluates to true if and only if v is Double.NaN (since NaN is not equal to itself). Thus, v != v is logically equivalent to Double.isNaN(v). Comparing them with == always yields true for any double value, printing 'true,true,true'.

Multiple choice technology programming languages
  1. doStuff x = 6 main x = 6

  2. doStuff x = 5 main x = 6

  3. doStuff x = 5 main x = 5

  4. Compilation fails

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

Java passes primitives by value. The main method passes x=5 to doStuff, which receives a copy. Inside doStuff, x++ increments the copy AFTER printing its current value (5). The original x in main remains unchanged. Output: 'doStuff x = 5' then 'main x = 5'. Option C is correct. If x were an object reference, behavior would differ.

Multiple choice technology programming languages
  1. null

  2. zero

  3. some

  4. Compilation fails

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

The code has a syntax error: 'else (str.length() == 0)' is invalid. The 'else' keyword cannot be followed by a condition in parentheses - that's 'else if'. This causes compilation failure. Option D is correct. If the syntax were corrected to 'else if', str='null' is not null and has length 4, so 'some' would print.

Multiple choice technology programming languages
  1. 2

  2. 2 3

  3. 1 2 3

  4. Compilation fails

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

The first if-condition (x == 4) && !b2 evaluates to false because x is 5, so '1' is not printed. Next, '2' is printed unconditionally. The second if-condition (b2 = true) && b1 assigns true to b2, making the expression true && true, which evaluates to true, so '3' is printed.

Multiple choice technology web technology
  1. The value of the 'test' variable will be 2.

  2. The value of the 'test' variable will be 0.

  3. The value of the 'test' variable will be 1.

  4. The variable 'test' must be declared at global scope, else a run-time error will occur

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

In JSP scriptlets, variables declared without explicit scope are local to the request. Each HTTP request reinitializes test to 0, then increments to 1. The third access still shows 1, not 3.

Multiple choice technology web technology
  1. The value of the 'test' variable will be 2.

  2. The value of the 'test' variable will be 0.

  3. The value of the 'test' variable will be 1.

  4. The variable 'test' must be declared at global scope, else a run-time error will occur

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

The JSP scriptlet <% int test = 0; %> declares a local variable inside the service method. Every time the page is requested, the variable is re-initialized to 0 and incremented to 1, so it always prints 1.