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

  2. 20

  3. 30

  4. 40

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

During instantiation of Derived, the Base constructor is called first, which invokes addValue(). Because of dynamic binding, the overridden addValue() in Derived runs, adding 20 to value. Then, the Derived constructor runs and calls addValue() again, adding another 20, resulting in 40.

Multiple choice technology programming languages
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints ‘foo”.

  4. The code executes normally, but nothing is printed.

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

Calling start() twice on the same Thread object throws IllegalThreadStateException at runtime. Once a thread has been started, subsequent calls to start() cause an exception - you cannot restart a thread.

Multiple choice technology programming languages
  1. n = 100;

  2. i.setX( 100);

  3. o.getY().setX( 100);

  4. i = new Inner(); i.setX( 100);

  5. o.setY( i); i = new Inner(); i.setX( 100);

  6. i = new Inner(); i.setX( 100); o.setY( i);

Reveal answer Fill a bubble to check yourself
B,C,F Correct answer
Explanation

The code passes an Inner object to Outer via setY(). Options B, C, and F all work: B modifies i directly before it was passed to o, C accesses the Inner through o and modifies it, and F creates a new Inner, modifies it, then replaces it in o. Options A, D, and E fail because they modify a different object or n (a primitive).

Multiple choice technology programming languages
  1. A

  2. B

  3. C

  4. D

  5. E

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

Option B: StringBuffer starts with '123456789', delete(0,3) removes '123' leaving '456789', replace(1,3,'24') affects positions 1-2 ('56') replacing with '24' resulting '424789', delete(4,6) removes '89' leaving '4247'. Option E: StringBuilder delete operations transform '123456789' to '4247'. Other options fail due to method chaining issues or incorrect indices.

Multiple choice technology programming languages
  1. c

  2. a

  3. ab

  4. ac

  5. bc

  6. abc

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

When NullPointerException occurs at line 34, it's caught by the first catch block (line 35-36) which prints 'a'. The finally block (line 39-40) always executes, printing 'c'. The output is 'ac'. The second catch block is skipped because the first one matches.

Multiple choice technology programming languages
  1. i=0 j=0

  2. i=0 j=1

  3. i=0 j=2

  4. i=1 j=0

  5. i=1 j=1

  6. i=1 j=2

Reveal answer Fill a bubble to check yourself
B,C,F Correct answer
Explanation

Tracing the loops: When i=0, j prints 2,1 before break at j=0. When i=1, j prints 2 before break at j=1. When i=2, j prints 2,1,0 but i=2 after loop ends. Output: i=0 j=2, i=0 j=1, i=1 j=2.

Multiple choice technology programming languages
  1. 0

  2. 1

  3. 2

  4. 3

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

The post-increment l++ assigns the current value 0 to k, then increments l to 1. Pre-increment ++k increments k to 1 first, then assigns 1 to j. Post-increment j++ assigns 1 to i, then increments j to 2. The output is 1.

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.