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. x = 42

  2. x = 43

  3. x = 44

  4. Compilation fails

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

The variable x is declared inside the try block, meaning its scope is limited to that block. It is inaccessible in the catch and finally blocks, causing a compilation error when referenced there. Additionally, the typo X++ (uppercase) and printIn (capital I) would also prevent compilation.

Multiple choice technology programming languages
  1. 1 1

  2. 2 1

  3. 3 1

  4. 4 1

  5. 2 3

  6. 4 3

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

For doX(s,s) with short arguments, boxing to Short (which inherits from Number) is preferred over varargs, resolving to doX(Number, Number) (returning 4). For doX(7,7) with int arguments, boxing to Integer is more specific than Number, resolving to doX(Integer, Integer) (returning 3). Thus, '4 3' is printed.

Multiple choice technology programming languages
  1. hi

  2. hi hi

  3. hi hi hi

  4. Compilation fails

  5. hi, followed by an exception

  6. hi hi, followed by an exception

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

m3.go() prints 'hi'. Then m4=m3.m1 is null since m1 was never initialized. Calling m4.go() throws a NullPointerException. The output is 'hi' followed by the exception.

Multiple choice technology programming languages
  1. true true

  2. true false

  3. false true

  4. false false

  5. Compilation fails.

  6. An exception is thrown at runtime.

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

f1 and f3 reference the same object (z is assigned x, and x is f1). So f1 == f3 is true. The 'final' keyword on f1 and z doesn't prevent modifying the object's fields - it only prevents reassigning the reference. z.x = 6 modifies the same object that f1 references, so f1.x == f3.x (both 6) is true.

Multiple choice technology programming languages
  1. 343 340 340

  2. 343 340 342

  3. 343 341 342

  4. 343 341 340

  5. 343 341 343

  6. Compilation fails.

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

First, static tooth (343L) is printed. Then the local final tooth (340L) is declared. doIt() receives 340, ++tooth makes it 341 (printed), then ++tooth makes it 342 (returned). Back in main, the local tooth is still 341 (not affected by doIt's parameter modifications). Output: 343 341 340.

Multiple choice technology programming languages
  1. Line 4

  2. Line 5

  3. Line 6

  4. Line 7

  5. Line 8

  6. Line 9

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

Java 5 introduced autoboxing and unboxing. In Java 1.4, assigning a primitive long to a Long object (Lines 7 and 8) or assigning a Long object to a primitive long (Line 4) without explicit conversion would fail to compile. These lines compile in Java 5 due to automatic boxing and unboxing.

Multiple choice technology programming languages
  1. float f=1.3;

  2. int i=10;

  3. char c="a";

  4. byte b=257;

  5. boolean b=null;

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

Only option B compiles cleanly. Option A requires 1.3f to avoid loss-of-precision warning. Option C uses double quotes for String instead of single quotes for char. Option D overflows byte range (-128 to 127). Option E is invalid because boolean is a primitive type and cannot be assigned null.

Multiple choice technology programming languages
  1. Error: anar is referenced before it is initialized

  2. null

  3. 0

  4. 5

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

In Java, when you create an int array using 'new int[5]', all elements are automatically initialized to 0 (the default value for int primitives). Therefore, anar[0] prints 0. This is not an error, not null, and not 5 (the array length, not a value).

Multiple choice technology programming languages
  1. The computer will output "0123...99"

  2. The computer will output "0123...100"

  3. The output is undefined

  4. Don't know

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

In C++, local variables like int x are not automatically initialized to zero. Reading from an uninitialized variable leads to undefined behavior, meaning the initial value of x is unpredictable and the output of the loop is completely undefined.

Multiple choice technology programming languages
  1. Outputs 12

  2. Outputs 10

  3. Outputs the address of v

  4. Compile error

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

The function receives a copy of the pointer to v. Inside the function, x is reassigned to a new memory address (new int), so modifying *x only changes the dynamically allocated integer, leaving the original variable v in main unchanged at 10.