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. prints object created

  2. Compile time error

  3. Runtime Excepion

  4. None of the above

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

This code is valid Java. A static interface can contain static member classes, and C1.I.C2 refers to that nested class. The object creation using new C1.I.C2() is valid syntax, and the program compiles and runs successfully, printing 'object created'.

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

  2. Prints: 1,0

  3. Prints: 0,1

  4. Compile-time error

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

In i = i++ + f1(i), the post-increment operator i++ returns the current value (0) then increments i to 1. So f1 receives 0, prints '0,', and returns 0. The expression becomes i = 0 + 0 = 0, but wait - after i++ executes, i becomes 1. So the right side evaluates to 0+0=0, then i (which is 1 from the increment) is assigned 0. Actually, let me trace more carefully: i starts at 0. i++ returns 0, then i becomes 1. f1(i) where i=1 now is called... but the parameter is evaluated before the increment? No, parameters are evaluated left to right. So f1 receives 0, prints '0,'. The expression is 0 + 0 = 0. i is set to 0. But the post-increment made i=1 temporarily, but then the assignment overwrites it. Output: '0,0'. Wait, option B says '1,0'. Let me reconsider. Actually Java evaluates i++ first (returns 0, i becomes 1), then evaluates f1(i) - but what's i at this point? It's 1. So f1(1) prints '1,' and returns 0. Then 0+0=0. Output: '1,0'.

Multiple choice technology programming languages
  1. compile time error

  2. Runtim error

  3. prints 8

  4. prints 0

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

The variable i2 is only assigned inside the if block, but it's declared outside. Java requires local variables to be definitely assigned before use. If i1 were less than or equal to 3, i2 would be uninitialized when println is called. This is a compile-time error.

Multiple choice technology programming languages
  1. compile time error at line 1

  2. compile time error at line 2

  3. the code compiles fine

  4. none of the above

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

An interface in Java can contain inner classes, which are implicitly public and static. The syntax in the snippet is fully valid, so the code compiles successfully.

Multiple choice technology programming languages
  1. Compile failure

  2. sucessfully compiled, but through exception in run time.

  3. It runs sucessfuly and prints "without the main method"

  4. It runs sucessfuly, but No output.

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

This is nearly identical to question 141060. The class name is now 'withoutmain' instead of 'WithoutMain' (capital W), but the class is still public. Java allows public classes. The static block executes when the class loads, prints the message, and System.exit(0) terminates before main is required. The program compiles and runs successfully.

Multiple choice technology programming languages
  1. compiletime error at lines 3,4,5

  2. compiltime error at line 4,5

  3. compiletime error at line 3

  4. Runtime Exception

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

In Java, array declarations cannot specify the array size on the left side of the assignment. Lines 4 and 5 violate this rule, causing compile-time errors. Line 3 is valid 2D array syntax.

Multiple choice technology programming languages
  1. prints object created

  2. Compile time error

  3. Runtime Excepion

  4. None of the above

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

In Java, interfaces can contain nested classes, which are implicitly static and public. The syntax for declaring and instantiating C1.I.C2 is correct, so it compiles and runs without issue.

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

  2. Prints: 1,0

  3. Prints: 0,1

  4. Compile-time error

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

Java evaluates expressions left-to-right. i++ returns 0 then increments i to 1. f1(i) is called with i=1, prints '1,' and returns 0. So i = 0 + 0 = 0. The post-increment result (0) is assigned to i, overwriting the increment. Output: 1,0

Multiple choice technology programming languages
  1. will cause a compiler error as the range of character is between 0 and 2^16 - 1. Will request for an explicit cast.

  2. will not cause a compiler error and c will have the value -1;

  3. c will not represent any ASCII character.

  4. c will still be a Unicode character.

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

In Java, char is an unsigned 16-bit type with range 0 to 65535. Assigning -1 requires an explicit cast because -1 is outside this range. Without casting, the compiler will reject the assignment.

Multiple choice technology programming languages
  1. compiletime error at lines 3,4,5

  2. compiltime error at line 4,5

  3. compiletime error at line 3

  4. Runtime Exception

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

Line 4 fails because C-style array initialization with size is invalid: 'int a2[4]={3,4,5,6};' - Java doesn't allow specifying size when initializing. Line 5 fails because 'a2' is already declared at line 4. Line 3 is valid syntax (though odd) - it declares a 2D array. The claimed answer is correct.

Multiple choice technology programming languages
  1. compiletime error at lines 1,2,3,4,5

  2. compiletime error at lines 2,3,4,5

  3. compiletime error at lines 2,3,4

  4. prints 3

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

Java does not allow access modifiers (private, protected, public) on local variables inside methods. These modifiers only apply to class members (fields and methods). Lines 2-4 are illegal because a, b, c are local variables in main() with access modifiers. Line 5 fails because those variables don't exist as declared.

Multiple choice technology programming languages
  1. Prints: ABC

  2. Prints BC and Runtime Exception

  3. Prints: BCD

  4. Runtime Exception

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

The java command runs with arguments: a1[0]="A", a1[1]="B", and a1[2]="C". The code tries to access a1[1], a1[2], and a1[3]. Accessing a1[3] throws an ArrayIndexOutOfBoundsException at runtime. Prior to the exception, it successfully prints a1[1] ('B') and a1[2] ('C').

Multiple choice technology programming languages
  1. prints 1,2

  2. prints 2,0

  3. prints 2,2

  4. compile time error

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

m1() declares local variable x=1 (not the static s). Java passes primitives by value, so m2(x) receives a copy - doubling x inside m2 doesn't affect m1's local x. m1 prints '1' then m2 stores 2 in static field s. Finally main prints s which is 2. Output: 1 2

Multiple choice technology programming languages
  1. No output

  2. 3 and 5

  3. 1, 3 and 5

  4. 3

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

In this switch statement, x=2 matches case 2 which has no break statement, causing fall-through to case 3 which prints "3" followed by another fall-through to case 5 which prints "5". The output is therefore "3" and "5" printed on separate lines.

Multiple choice technology programming languages
  1. Null Pointer exception

  2. In message

  3. Compiler error

  4. No output

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

Static methods belong to the class, not to instances. When you call a.message() on a null reference, Java doesn't throw a NullPointerException because the call is resolved at compile-time based on the declared type (TestStatic), not the runtime value of the reference.