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. output Positive infinity

  2. output Negative infinity

  3. Will fail to compile

  4. Runtime exception

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

In Java, when dividing integers, division by zero throws ArithmeticException at runtime. The expression 10 / 0 involves two int literals, so integer division rules apply and the exception is thrown before any assignment to the double variable occurs. Floating-point division by zero would produce Infinity, but that requires at least one floating-point operand.

Multiple choice technology programming languages
  1. a. Leve1,Level 2,Level 1 Finished

  2. b. Level,Leve2,Leve 2 Finished

  3. c. Level 1,Level 2,Leve 2 Finished,Level 1 Finished

  4. d.Error

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

To understand the output of this code, we need to examine the nested try-finally blocks and the use of the goto statement.

The code first prints "Level 1", then enters a try block. Within that try block, it prints "Level 2", then jumps to the "exit" label using a goto statement. This causes the finally block within the inner try block to execute, which prints "Level 2 Finished".

After the inner finally block completes, the outer finally block executes, which prints "Level 1 Finished". Thus, the final output of the code will be:

Level 1 Level 2 Level 2 Finished Level 1 Finished

Therefore, the correct answer is:

The Answer is: C. Level 1, Level 2, Level 2 Finished, Level 1 Finished

Multiple choice technology
  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 reads each token sequentially using space as delimiter: 'hello' as String, 1 as int, 2.00 as float (formatted as 2.0), and false as boolean. The println concatenates these with colons between values.

Multiple choice technology
  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 1 compiles (raw type array with warning). Line 3 compiles (raw type assignment). Line 4 compiles (unchecked cast from raw type). Line 5 fails because you cannot cast Gen to Gen - Java disallows conversion between different parameterized generic types even with a cast.

Multiple choice technology
  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

In switch statements without a matching case, execution falls through to the default case, then continues to subsequent cases unless break is encountered. Since i=9 matches no case, default executes (prints 'default'), then execution continues to case 0 (prints 'zero') where break stops it.

Multiple choice technology
  1. myprog

  2. good

  3. morning

  4. Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"

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

The code provided is a Java program that takes command line arguments and prints the value of the argument at index 2.

The command line used to run the program is:

java myprog good morning

In this case, the command line arguments are "good" and "morning".

The program tries to print the value at index 2 of the argv array, which corresponds to the third command line argument.

However, the argv array only has two elements: "good" at index 0 and "morning" at index 1. There is no element at index 2.

Therefore, when the code tries to access argv[2], it will raise an ArrayIndexOutOfBoundsException because the index is out of bounds.

So, the correct answer is D) Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2".

Multiple choice technology
  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, array elements are automatically initialized to default values when the array is created. For int arrays, all elements are initialized to 0. The code prints anar[0] which is 0, not null (that's for object arrays).

Multiple choice technology
  1. a sequence of 5 0's will be printed

  2. Error: ar is used before it is initialized

  3. Error Mine must be declared abstract

  4. IndexOutOfBoundes Error

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

Mine extends abstract class MineBase but doesn't implement the abstract method amethod(). Therefore Mine must also be declared abstract. If a class doesn't implement all abstract methods from its parent, it must be abstract.

Multiple choice technology
  1. a)

  2. b)

  3. c)

  4. none

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

To solve this question, the user needs to know the basic syntax of Java programming language such as data types, logical operators, and conditional statements.

a) This option will not compile because the condition inside the if statement is of type integer, whereas Java expects a boolean condition. The condition should be a boolean expression that evaluates to true or false.

b) This option will compile without error. It declares two boolean variables and compares them using the equality operator (==). Since both variables have the same value (true), the condition evaluates to true and the statement inside the if block is executed.

c) This option will not compile because it contains a logical operator error. The logical OR operator in Java is represented by two vertical bars (||), not a single vertical bar followed by an ampersand (|&). The correct expression is (i==1 || j==2).

Therefore, the correct answer is:

The Answer is: B

Multiple choice technology
  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 the file isn't found, FileNotFoundException is caught, 'No such file found' is printed, then -1 is returned. However, the finally block ALWAYS executes before the return, so 'Doing finally' is printed first. Output order: catch message → finally message → return value.

Multiple choice technology
  1. On the line After //One put Base(10);

  2. On the line After //One put super(10);

  3. On the line After //Two put super(10);

  4. On the line After //Three put super(10);

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

To call a specific superclass constructor from a subclass constructor, use super(args) as the FIRST statement in the subclass constructor body. Option C places super(10) after //Two which is inside the Sup() constructor, correctly invoking Base(int i).

Multiple choice technology
  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 doPlay() method declares int x but doesn't initialize it before using ++x. This is a compile-time error, unlike instance variables which receive default values. The ++x operator attempts to read x's current value before incrementing, but x has no value.

Multiple choice technology
  1. XAM is printed

  2. exam is printed

  3. Compiler Error

  4. Nothing is printed

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

The comma operator evaluates all operands and returns the value of the last one. The expression (a,b,x,y) evaluates to y=0, which is false. Therefore, the if condition is false and nothing is printed. Note that void main() and missing return are not valid C but are accepted by some compilers as extensions.