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. A) Strings are immutable, compilation error at line 3.

  2. B) Strings are immutable, runtime exception at line 3.

  3. C) Prints "Welcome".

  4. D) Prints "Welcome to Java!".

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

Java strings are immutable. Calling str.concat(" to Java!") creates and returns a new string object, but does not modify the original reference str. Therefore, printing str outputs the original value "Welcome".

Multiple choice technology programming languages
  1. Compilation error at line 3.

  2. Compilation error at line 10.

  3. No compilation error, but runtime exception at line 3.

  4. No compilation error, but runtime exception at line 10.

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

Static methods belong to the class, not instances, and cannot be overridden. They can only be hidden by declaring a static method with the same signature in the subclass. Attempting to override a static method with an instance method (missing static keyword) causes a compilation error.

Multiple choice technology programming languages
  1. Compilation error, variable "i" declared twice.

  2. Compilation error, static initializers for initialization purpose only.

  3. Prints 10.

  4. Prints 20.

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

The static initializer block declares a local variable i that shadows the instance variable. This is valid Java - local variables can shadow instance variables within their scope. The instance variable i remains unchanged (20). When main runs, a.i prints the instance variable value, which is 20.

Multiple choice technology programming languages
  1. true true

  2. false true

  3. true false

  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

The final keyword on f1 prevents reassigning the reference, but its fields can still be modified. z = x makes z refer to the same object as f1, so z.x = 6 changes f1.x to 6. Returning z returns the same object f1 refers to. Thus f1 == f3 is true (same reference) and f1.x == f3.x compares 6 == 6, also true.

Multiple choice technology programming languages
  1. 1 1

  2. 1 2

  3. 2 1

  4. 2 2

  5. 4 1

  6. 4 2

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

First expression: (y * 2) % x = (7 * 2) % 5 = 14 % 5 = 4 (remainder of 14 divided by 5). Second expression: y % x = 7 % 5 = 2 (remainder of 7 divided by 5). The output is 4 2, with a space between the two print results.

Multiple choice technology programming languages
  1. Veronica Wallace Duncan

  2. Veronica Wallace Duncan 42

  3. Duncan Wallace Veronica

  4. 42 Duncan Wallace Veronica

  5. Compilation fails

  6. An exception occurs at runtime.

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

The showAll method uses a raw Queue type (no generics), which bypasses compile-time type checking. This allows adding an Integer to what was originally a Queue. Elements are removed in FIFO order and concatenated with spaces.

Multiple choice technology web technology
  1. Compiler error complaining about access restriction of private variables of AQuestion

  2. Compiler error complaining about forward referencing

  3. No Compilation error - The output is 0;

  4. No Compilation error - The output is 10;

Reveal answer Fill a bubble to check yourself
A,B,C,D Correct answer
Multiple choice technology programming languages
  1. Compiler error complaining about the catch block where no IOException object can ever be thrown.

  2. Compiler error - IOException not found. It must be imported in the first line of the code.

  3. No compiler error. The lines “Before Try” and “At the end” are printed on the screen.

  4. None of Above

Reveal answer Fill a bubble to check yourself
A,B,C,D Correct answer
Multiple choice technology programming languages
  1. b=m;

  2. m=b;

  3. d =i;

  4. b1 =i;

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

Since Base extends MyCast, a reference of type MyCast can point to an instance of Base (upcasting). Therefore, m = b; is perfectly valid and compiles without error. Downcasting b = m; requires an explicit cast.

Multiple choice technology programming languages
  1. Code will give compile time error

  2. Code will give runtime error

  3. Code will print "Equal"

  4. Code will print "Not Equal" ==

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

The toString() method on a string literal returns the same string instance, and string literals are interned in Java, making both reference equality and content comparison true, which prints Equal.

Multiple choice technology programming languages
  1. Code will give compile time error

  2. Code will give runtime error

  3. Code will print "Equal"

  4. Code will print "Not Equal"

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

In Java, String's toString() method returns the same String object (this). The expression "String".toString() returns the literal "String" itself. Since it's the same literal, the == comparison returns true, so the code prints "Equal". The == operator compares object references for String, not content.

Multiple choice technology programming languages
  1. Run-Time Error

  2. Compile-Time Error

  3. 1 2 3 4

  4. None of above

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

The program declares four integer variables (a=1, b=2, c=3, d=4) and prints them using two printf statements. The first printf outputs a and b, the second outputs c and d with a leading space. The output is 1 2 3 4. Option A and B are incorrect because the code compiles and runs without errors. Option D is incorrect because option C is valid.

Multiple choice technology programming languages
  1. 0 3 -3

  2. Compile-Time Error

  3. 0 3 -1

  4. 0 3 0

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

The expression uses the comma operator which evaluates left operand and returns right operand. --a is prefix decrement so a becomes 0. b++ is postfix increment so b returns 2 then becomes 3. The comma expression (--a, b++) returns 2. Then c = 2 - 3 = -1. Output: a=0, b=3, c=-1. Option A is wrong (c=-3 incorrect). Option D is wrong (c=0 incorrect).

Multiple choice technology programming languages
  1. Compile-Time Error

  2. 10

  3. 6

  4. 2

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

Evaluate comma expressions left to right, returning rightmost value. (a,a) returns a=1. (b,c) returns c=3. (c,d) returns d=4. (d,b) returns b=2. So e = 1 + 3 + 4 - 2 = 6. Option A is wrong - no compile error. Option B would require different arithmetic. Option D is incorrect.