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. Reboot the Machine

  2. Disable the print screen key

  3. Change the default screen color

  4. puts Capslock on

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

In DOS/BIOS environments, memory address 0x417 (segment 0x0000, offset 0x0417) is the BIOS keyboard data area that stores the keyboard shift status byte. The bits in this byte control toggle keys like CapsLock, NumLock, ScrollLock. Setting bit 6 (value 64) turns on CapsLock. This is a direct hardware manipulation through memory-mapped I/O.

Multiple choice technology programming languages
  1. 5

  2. garbage value

  3. compile error

  4. 2

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

The expression ++(a+1) breaks down as: (a+1) points to the second row {4,5,6}, (a+1) gives the address of the first element of that row, *(a+1) dereferences to get the value 4, and ++ pre-increments it to 5 before printf uses it. The array is modified, and 5 is printed.

Multiple choice technology programming languages
  1. Compilation fails due to error at line 1,2,3,4

  2. Compilation fails due to error at line 3,4

  3. Compiles fine and exception is thrown at runtime.

  4. Compiles fine and prints "check check 20.01"

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

To solve this question, the user needs to understand the concepts of Hashtable and data types in Java.

The code creates a Hashtable named ht, which maps keys to values. It puts three key-value pairs into the Hashtable:

  • "chec" is mapped to "check"
  • 1000 is mapped to "check"
  • "check" is mapped to 20.01

The code then retrieves the values corresponding to three keys and prints them out.

Now let's go through each option and explain why it is right or wrong:

Option A: Compilation fails due to error at line 1,2,3,4 This option is incorrect. There are no compilation errors in this code.

Option B: Compilation fails due to error at line 3,4 This option is incorrect. There are no compilation errors in this code.

Option C: Compiles fine and exception is thrown at runtime. This option is incorrect. The code compiles without errors, but no exception is thrown at runtime. The output of the code is "check check 20.01".

Option D: Compiles fine and prints "check check 20.01" This option is correct. The code compiles without errors, and when run, it prints "check check 20.01". The keys "chec" and 1000 are mapped to the value "check", while the key "check" is mapped to the value 20.01.

Therefore, the answer is: D. Compiles fine and prints "check check 20.01".

Multiple choice technology embedded technologies
  1. A) Compilation error at line 3

  2. B) Prints 23, 5, 5 and 23.

  3. C) Prints 5, 5, 5 and 23.

  4. D) Prints 23, 5, 23 and 23.

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

Line 1 performs string concatenation, yielding " 23". Line 2 adds integers, outputting 5. Line 3 adds integers first (5) then appends a string, outputting "5". Line 4 concatenates 2, an empty string, and 3, outputting "23".

Multiple choice technology programming languages
  1. A. It would fail to compile

  2. B. It would generate a run-time error on execution.

  3. C. It would execute, but ask the user to specify the directory in which to create ll.txt.

  4. D. It would execute without an error and print "hi" to a file called ll.txt

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

FileOutputStream creates the file if it doesn't exist and opens it for writing. PrintStream wraps this output stream and provides convenient methods like println. The code successfully creates ll.txt and writes hi to it. No exceptions occur because the throws Exception clause handles any IOException.

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.