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. static public void main(String[] args) { /* ... */ }

  2. public static int main(String[] args) { /* ... */ }

  3. public static void main(String args) { /* ... */ }

  4. public int main(Strings[] args, int argc) { /* ... */ }

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

Java's main method must be public, static, void, and accept String[] as parameter. The order of public and static can be swapped. Options B and D incorrectly use int as return type, while C uses String instead of String[].

Multiple choice technology programming languages
  1. The name of the program

  2. The number of arguments

  3. The first argument if one is present

  4. All the arguments

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

In Java's main(String[] args), args[0] is the first command-line argument passed to the program. Unlike C/C++, Java does not include the program name in the args array. If no arguments are provided, the array is empty and accessing args[0] would throw ArrayIndexOutOfBoundsException.

Multiple choice technology programming languages
  1. +VE GREATER THAN -VE

  2. +VE LESS THAN -VE

  3. Compile error

  4. Edited Numeric field cannot be used for comparison.

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

The code will produce a compilation error. The PIC clauses PIC +9(2).99 and PIC -9(2).99 are invalid COBOL syntax. In COBOL, to define signed numeric fields, you use 'S' as a separate sign clause prefix (e.g., PIC S9(2).99), not + or - symbols embedded in the PIC clause. The + and - symbols are used in editing (output formatting), not in data definition clauses.

Multiple choice technology programming languages
  1. final

  2. static

  3. native

  4. public

  5. private

  6. abstract

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

Explanation: In Java, an interface can only have public abstract methods and public static final fields. Therefore, on line 12, we can have only public, static, and final keywords. The correct answer options are D) public.

Option A) final - This option is correct because final keyword can be used only with the variables and methods

Option B) static - This option is correct because static keyword can be used with an interface.

Option C) native - This option is incorrect because native keyword is not allowed.

Option D) public - This option is correct because public keyword can be used

Option E) private - This option is incorrect because private keyword is not allowed

Option F) abstract - This option is incorrect because abstract keyword is not allowed.

Therefore, the correct options are B) static, D) public, and A) final.

Multiple choice technology programming languages
  1. 2

  2. 3

  3. 1 2

  4. 2 3

  5. 1 2 3

  6. Compilation fails.

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

The first if condition ((x==4) && !b2) evaluates to false because x==4 is false (x is 5), so the short-circuit && doesn't evaluate !b2 and "1" is not printed. Line 19 prints "2" unconditionally. The second if ((b2 = true) && b1) first assigns true to b2, then evaluates (true && b1) which is true since b1 is true, so "3" is printed. Final output: "2 3". Option E is incorrect because the first condition is false. Option F is incorrect - the code compiles and runs successfully.

Multiple choice technology programming languages
  1. HaHa

  2. Ha169

  3. Ha Ha

  4. 169Ha

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

The first print uses String concatenation: "H" + "a" = "Ha". The second print adds two char values: 'H' (ASCII 72) + 'a' (ASCII 97) = 169. When char values are added with + operator, they're promoted to int, so the result is the integer 169. Options A, C, and D are incorrect - they don't account for the char addition producing an integer sum.

Multiple choice technology programming languages
  1. ABC easy as [C@3e25a5

  2. ABC easy as 123

  3. ABC easy as 1 2 3

  4. ABC easy as 1,2,3

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

When concatenating a String with a char array using + operator, Java calls toString() on the char array, which doesn't return the array contents but rather its default Object toString() format (className + hexadecimal hash code). So "ABC easy as " + numbers produces "ABC easy as [C@3e25a5" (or similar hash). Options B, C, and D are incorrect - char arrays are not automatically converted to their string contents in concatenation. You need to use Arrays.toString() or new String(char[]) to get the actual characters.

Multiple choice technology programming languages
  1. True

  2. False

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

In Java, the + operator has higher precedence than the == operator. The expression evaluates as ("Animals are equal: " + pig) == dog. This compares a newly created concatenated string to dog, resulting in false.

Multiple choice technology programming languages
  1. 99

  2. 0

  3. 100

  4. 101

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

The key issue is the post-increment operator j = j++. The post-increment operator returns the original value of j, then increments it. So j = j++ assigns the original value of j back to j, effectively doing nothing. After 100 iterations, j remains 0. Options A, C, and D are incorrect - they don't understand that the post-increment returns the original value before incrementing.

Multiple choice technology programming languages
  1. 32

  2. Infinite Loop

  3. 16

  4. 64

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

The left shift operator on -1 produces a value that is never equal to 0. In two's complement representation, -1 is all 1s (binary: 111...111). Left-shifting -1 by any amount still produces -1 (or eventually causes overflow/undefined behavior), but it will never become 0. The condition -1 << i != 0 is always true, so the while loop never terminates. Options A, C, and D are incorrect - they assume the loop terminates after a certain number of iterations.

Multiple choice technology programming languages
  1. True

  2. False

  3. Compilation Error

  4. Run Time Error

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

In Java, when a finally block executes with a return statement, it overrides any return value from the try block. The try block executes return true, but before the method actually returns, the finally block executes and returns false, which overrides the true. The final output is false. Options A, C, and D are incorrect - the finally block's return takes precedence, there's no compilation error, and no runtime error occurs.

Multiple choice technology programming languages
  1. Hello world \n Goodbye world

  2. Hello world

  3. Compilation Error

  4. Run Time Error

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

System.exit() immediately terminates the JVM, bypassing the finally block. Only Hello world prints before exit(). The finally block never executes because System.exit() halts the program abruptly, skipping all normal cleanup including finally blocks.

Multiple choice technology programming languages
  1. Derived

  2. Compilation Error in Main mehod

  3. Compilation Error due to Derived class

  4. Run Time Error

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

The code fails to compile in the main method. Since main is static, it cannot instantiate the non-static inner class Derived without an instance of Quiz8. Also, Derived.className is private and cannot be accessed from main directly.

Multiple choice technology programming languages
  1. 99

  2. 100

  3. 0

  4. 101

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

The for loop iterates 100 times (i from 0 to 99). Each iteration increments j by 1, starting from 0. After the loop completes, j equals 100. This is a simple counter loop where the loop variable i controls the number of iterations.