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 architecture
  1. 5

  2. 6

  3. Compile error

  4. Runtime error

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

The local variable x in doPlay() is declared but never initialized before being used in the expression ++x. Java requires local variables to be initialized before use. The instance variable int x=5 is shadowed by the local int x declaration, so the class field is not relevant here.

Multiple choice technology architecture
  1. The program will output 'hello:1:2.0:false'

  2. The program will throw Input Mismatch exception at the run-time

  3. The program will output nothing.

  4. The program will ouput ':1:2.0:false'

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

The Scanner is initialized with the string 'hello 1 2.00 false' and uses space as delimiter. scanner.next() returns 'hello', scanner.nextInt() returns 1, scanner.nextFloat() returns 2.0 (note: when printed, float 2.00 displays as 2.0), and scanner.nextBoolean() returns false. These are concatenated with colons, producing 'hello:1:2.0:false'. No InputMismatchException occurs because the data types match the scanner method calls.

Multiple choice technology architecture
  1. Compile time Error at line 1

  2. Compile time Error at line 3

  3. Compile time Error at line 4

  4. Compile time Error at line 5

  5. Run Time Error

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

Line 5 attempts to cast a Gen to Gen. While line 4's raw type cast compiles with a warning, line 5 is a compile-time error because you cannot directly cast a parameterized type of one generic type to another. The compiler enforces type safety - Gen and Gen are incompatible types. The error occurs at compile time because generics are erased but type checking happens during compilation to ensure type safety.

Multiple choice technology architecture
  1. default

  2. default, zero

  3. error default clause not defined

  4. no output displayed

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

When the switch expression i=9 doesn't match any case label (0, 1, or 2), execution falls through to the default case. The default case prints 'default' but has no break statement, so execution continues to the next case (case 0) which prints 'zero'. The break after case 0 stops further fallthrough. Therefore the output is 'default' followed by 'zero' on the next line.

Multiple choice technology architecture
  1. Error: anar is referenced before it is initialized

  2. null

  3. 0

  4. 5

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

In Java, when an array is instantiated with 'new int[5]', all elements are automatically initialized to the default value for the type. For int arrays, the default value is 0. Therefore anar[0] contains 0. The variable 'anar' is properly initialized (not null), so there's no compilation error or null reference.

Multiple choice technology architecture
  1. No such file found

  2. No such file found ,-1

  3. No such file found, Doing finally, -1

  4. 0

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

When Hello.txt doesn't exist, FileInputStream throws FileNotFoundException. The catch block for FileNotFoundException executes, printing 'No such file found' and returning -1. Before returning, the finally block executes, printing 'Doing finally'. The return -1 completes after finally. Therefore output is: 'No such file found' then 'Doing finally' then the method returns -1. Note: The main method prints the return value, so we see -1 after 'Doing finally'.

Multiple choice technology architecture
  1. 5

  2. 6

  3. Compile error

  4. Runtime error

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

Local variables in Java must be initialized before use. The code declares 'int x' in doPlay() but doesn't assign it a value before using '++x'. This causes a compile-time error. The instance variable 'x=5' is shadowed by the local declaration and is not accessed.

Multiple choice technology architecture
  1. x=10, y=10

  2. x=55,y=55

  3. x=10,y=55

  4. None of the above.

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

In JavaScript, the + operator behaves differently based on operand types. When both operands are numbers (5+5), it performs arithmetic addition yielding 10. When both operands are strings ('5'+'5'), it performs string concatenation yielding '55'. This is a classic example of type coercion in JavaScript.

Multiple choice technology programming languages
  1. t t1

  2. t1 t

  3. t t

  4. Compilation succeed but Runtime Exception

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

Thread priorities in Java must be between 1 (MIN_PRIORITY) and 10 (MAX_PRIORITY). The call t1.setPriority(-3) throws IllegalArgumentException at runtime because -3 is outside the valid range. Compilation succeeds since it's syntactically valid.

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 doesn't allow method overloading based solely on return type. Both methods have the same name and no parameters, so this is a compile-time error regardless of the different return types (String vs StringBuffer).

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 pattern a*b means zero or more 'a' characters followed by 'b'. The string b matches because it has zero 'a's (valid) followed by 'b'. The matches() method returns true when the entire input matches the pattern.