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. Value of a is 7

  2. Compile Error - not able to access private member.

  3. Runtime Exception

  4. Value of a is 8

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

In Java, a non-static inner class holds an implicit reference to its enclosing outer class instance. Consequently, inner classes can directly access all members of the outer class, including those declared with private access modifiers, allowing the display of a as 7.

Multiple choice technology programming languages
  1. Compile with error

  2. USA

  3. UK

  4. Runtime Exception

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

Java uses method signature (name + parameter types) to distinguish methods. Return type alone cannot differentiate overloaded methods. Two getCountryName() methods with identical parameter lists (both empty) are ambiguous, causing a compilation error regardless of return types.

Multiple choice technology programming languages
  1. true

  2. compile error

  3. false

  4. b

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

The regex 'a*b' matches zero or more 'a' characters followed by 'b'. The input string 'b' contains zero 'a's followed by 'b', which satisfies this pattern. The matches() method returns true when the entire input matches the pattern.

Multiple choice technology programming languages
  1. 1 2 red blue

  2. Compile Error - because Scanner is not defind in java.

  3. 1 fish 2 fish red fish blue fish

  4. 1 fish 2 fish red blue fish

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

To solve this question, the user needs to understand how the Scanner class works in Java and how the useDelimiter() method works.

The useDelimiter() method sets the delimiter pattern for the Scanner object to use when breaking down input into tokens. In this case, the delimiter pattern is set to "\s*fish\s*", which means that the Scanner object will split the input string whenever it encounters the word "fish" surrounded by any number of whitespace characters.

The code then uses the nextInt() and next() methods of the Scanner object to retrieve the tokens that were split from the input string.

Let's go through each option to determine the correct answer:

A. 1 2 red blue: This option is correct. The first call to nextInt() retrieves the integer "1" that comes before the first occurrence of "fish". The second call to nextInt() retrieves the integer "2" that comes after the first occurrence of "fish". The first call to next() retrieves the word "red", and the second call to next() retrieves the word "blue".

B. Compile Error - because Scanner is not defined in java.: This option is incorrect. The Scanner class is defined in Java, so this code will not produce a compile error due to the use of Scanner.

C. 1 fish 2 fish red fish blue fish: This option is incorrect. The code does not print out the entire input string, but rather it retrieves specific tokens from the input string using the nextInt() and next() methods.

D. 1 fish 2 fish red blue fish: This option is incorrect. The second call to nextInt() retrieves the integer "2", which comes after the first occurrence of "fish". The first call to next() retrieves the word "red", and the second call to next() retrieves the word "blue".

Therefore, the correct answer is:

The Answer is: A. 1 2 red blue

Multiple choice technology programming languages
  1. Does not compile

  2. Throws IllegalFormatConversionException

  3. Prints 222.46

  4. Prints 222.45

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

The syntax System.out.printf("% .2f", d) uses a space flag, which prefixes positive numbers with a space, and .2 specifying two decimal places. The double value 222.4578 is formatted and rounded to two decimal places, outputting 222.46 (with a leading space), meaning it compiles and prints 222.46.

Multiple choice technology programming languages
  1. Compiler error

  2. FileNotFoundException thrown at line 1

  3. IOException thrown at line 2

  4. None of these

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

FileWriter creates the file if it doesn't exist, so no FileNotFoundException is thrown. The code compiles without errors and runs successfully. The write(1) call writes the character representation of integer 1, not the binary value. All options A, B, and C are incorrect because no compiler error, no FileNotFoundException at line 1, and no IOException at line 2 occur.

Multiple choice technology programming languages
  1. 5,4

  2. -4,4

  3. -5,4

  4. -4,5

  5. Compilation Error

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

The post-decrement operator a-- returns the original value of a (which is 5) and then decrements a to 4. Thus, num = -5. The printf statement outputs num followed by a, resulting in -5 4.