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. Run Time Error

  2. Compiler Error

  3. StackOverflow Exception

  4. NONE

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

In VB.NET, the constructor New in Myclass is declared as Private. In the Test class, Main tries to instantiate Myclass using New Myclass(10). Because the constructor is private, it is inaccessible from outside the class, causing a compiler error.

Multiple choice technology programming languages
  1. Compilation error, attempting to perform binary comparison on logical data type.

  2. Compilation and output of "We are equal 10".

  3. Compilation and output of "Not equal! 20".

  4. Compilation and output of "Not equal! 10".

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

The code uses the && operator which short-circuits. Since b1 is false, the right side ((Output += 10) == 20) is never evaluated. Output remains 10, not 20. The condition is false, so the else block executes, printing 'Not equal! 10'. The key is understanding short-circuit evaluation with && - if the left operand is false, the right is skipped.

Multiple choice technology programming languages
  1. prints: Value is - 9

  2. prints: Value is - 5

  3. Compilation error

  4. None of these

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

In the ternary expression, since one operand is double (9.9) and the other is int (9), the int is promoted to double, evaluating the expression to 9.0. Since Value is - 9.0 is not listed, 'None of these' is correct.

Multiple choice technology programming languages
  1. The code compiles and produces output: int version.

  2. Line 9 will not compile as there is no version of myMethod which takes a char as argument.

  3. An exception at line 9.

  4. Line 4 will not compile as void methods can't be overridden.

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

Java performs widening conversion from char to int when no exact method match exists. The primitive char type is promoted to int to match myMethod(int), not String, because String is an object reference type.

Multiple choice technology programming languages
  1. Compile successfully, nothing is printed

  2. Runtime error

  3. Compilation error

  4. Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo

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

IllegalAccessException is a checked exception in Java. Any method throwing a checked exception must either declare it with a throws clause or catch it - throwMethod does neither, causing compilation error.

Multiple choice technology programming languages
  1. 0122

  2. 0123

  3. Compilation error

  4. None of these

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

The loop variable i is scoped to the for-loop block only. Attempting to access i outside the loop violates Java's scoping rules - local variables declared in loop initialization are not visible after the loop terminates.

Multiple choice technology programming languages
  1. 0122

  2. 0123

  3. Compilation error

  4. None of these

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

The variable i is declared within the initialization of the for loop, meaning its scope is restricted to the loop body. Referencing i outside the loop in the subsequent print statement causes a compilation error, making other choices incorrect.

Multiple choice technology programming languages
  1. Hello World

  2. out.print("Hello World");

  3. No output is generated by this line

  4. "Hello World"

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

The syntax <%-- ... --%> represents a JSP comment, which is processed entirely server-side and ignored during compilation, resulting in no output. The distractors are incorrect because they assume the code executes or outputs the string literal, which only occurs with scriptlets or expressions.

Multiple choice technology programming languages
  1. 2

  2. 1 2

  3. 2 3

  4. 1 2 3

  5. Compilation fails.

  6. Exception is thrown at runtime

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

The first condition (x==4) is false since x=5, so '1' is not printed. '2' always prints. The second if assigns b2=true and checks b1=true, so both conditions are true and '3' prints. Output is '2 3'. Note the assignment (b2=true) inside the condition.

Multiple choice technology programming languages
  1. args.count

  2. args.length

  3. args.count()

  4. args.length()

  5. args.getLength()

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

In Java, the args parameter is an array. Arrays have a length property (not a method), so args.length returns the number of command-line arguments. The other options use incorrect syntax like count(), getLength(), or treating length as a method.