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 web technology
  1. 0 1 2 3

  2. 1 1 1 3 3

  3. 0 1 1 1 2 3 3

  4. 1 1 1 3 3 4 4 4

  5. 0 1 1 1 2 3 3 4 4 4

  6. Compilation fails

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

When j=0, k=0: prints '0', then j==0 breaks inner loop. Next, j=1: inner loop runs for k=0, 1, 2, printing '1 1 1'. Next, j=2, k=0: prints '2', then j==2 breaks. Next, j=3, k=0: prints '3'. For k=1: prints '3', and j==3 && k==1 triggers break foreach, terminating the outer loop. Output is ' 0 1 1 1 2 3 3'.

Multiple choice technology web technology
  1. TUE

  2. Wed

  3. The output is unpredictable

  4. Compilation fails due to an error on line 4

  5. Compilation fails due to an error on line 6

  6. Compilation fails due to an error on line 8

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

The enum Days has values: MON(0), TUE(1), WED(2). The array d2 from Days.values() has these in declaration order. Accessing d2[2] returns the third element WED. Option B is correct. The code compiles and runs fine - Days.values() is valid, enums can have arrays, and accessing index 2 is within bounds (array length is 3). Option A is TUE (index 1). Option C is wrong - enum order is fixed.

Multiple choice technology programming languages
  1. compiler error

  2. smaller type is promoted

  3. must explicitly cast

  4. none of the above

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

When comparing primitives of different numeric types, Java applies binary numeric promotion - the smaller type is automatically promoted (widened) to the larger type. For example, comparing int and long promotes the int to long. No explicit cast is needed.

Multiple choice technology web technology
  1. List<List<Integer>> table = new List<List<Integer>>();

  2. List<List<Integer>> table = new ArrayList<List<Integer>>();

  3. List<List<Integer>> table = new ArrayList<ArrayList<Integer>>();

  4. List<List, Integer> table = new List<List, Integer>();

  5. List<List, Integer> table = new ArrayList<List, Integer>();

  6. List<List, Integer> table = new ArrayList<ArrayList, Integer>();

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

The code requires table to be a List of List. Option B declares List> table = new ArrayList>() which is valid - ArrayList implements List, and you can parameterize it with List since ArrayList> is a subtype of List>. Option A fails because List is abstract. Option C is overly specific (ArrayList> cannot be assigned to List>). Options D and F use invalid syntax with comma-separated type parameters.

Multiple choice technology web technology
  1. 0 1 2 3

  2. 1 1 1 3 3

  3. 0 1 1 1 2 3 3

  4. 1 1 1 3 3 4 4 4

  5. 0 1 1 1 2 3 3 4 4 4

  6. Compilation fails

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

The outer loop has labeled 'foreach'. j=0: inner loop runs once, prints ' 0', then break (j==0) exits inner loop. j=1: inner loop completes (k=0,1,2), prints ' 1' three times. j=2: inner loop runs once, prints ' 2', then break exits. j=3: k=0 prints ' 3', k=1 triggers break foreach (exits outer loop). Output: 0 1 1 1 2 3 3.

Multiple choice technology web technology
  1. TUE

  2. Wed

  3. The output is unpredictable

  4. Compilation fails due to an error on line 4

  5. Compilation fails due to an error on line 6

  6. Compilation fails due to an error on line 8

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

Days.values() returns [MON, TUE, WED] in declaration order. Index 2 (0-based) is WED. The empty for-each loop is valid Java syntax. The output is 'WED'.

Multiple choice technology programming languages
  1. compiler error

  2. smaller type is promoted

  3. must explicitly cast

  4. none of the above

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

In Java, when comparing two different primitive numerical types (such as int and double), binary numeric promotion automatically promotes the operand with the smaller range or precision to match the larger/wider type before the comparison is executed, preventing compile errors.

Multiple choice technology web technology
  1. As the code stands it will not compile

  2. As the code stands the output will be 2

  3. As the code stands the output will be 3

  4. If the hashCode() method is uncommented the output will be 2

  5. If the hashCode() method is uncommented the output will be 3

  6. If the hashCode() method is uncommented the code will not compile

Reveal answer Fill a bubble to check yourself
C,D Correct answer
Multiple choice technology web technology
  1. ArrayList<Integer> input = null; ArrayList<Integer> output = null;

  2. ArrayList<Integer> input = null; List<Integer> output = null;

  3. ArrayList<Integer> input = null; List<Number> output = null;

  4. List<Number> input = null; ArrayList<Integer> output = null;

  5. List<Number> input = null; List<Number> output = null;

  6. List<Integer> input = null; List<Integer> output = null;

Reveal answer Fill a bubble to check yourself
B,E,F Correct answer
Explanation

The method returns List where E is inferred from the type parameter of the input List. Thus, the output type must be List (or a supertype like Collection), not a concrete subtype like ArrayList. Also, the type parameter of input and output must match exactly.

Multiple choice technology programming languages
  1. 1,3

  2. 2,3

  3. Compilation Error

  4. Exception

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

To solve this question, the user needs to know the basics of boolean expressions and how they work in Java programming. They also need to understand the concept of conditional statements.

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

The code starts by initializing the variable x to 5, and the boolean variables b1 and b2 to true and false, respectively.

The first conditional statement checks if the value of x is equal to 4 and if b2 is false. Since neither condition is true, the code skips the first print statement and moves on to the second one.

The second print statement prints "2" to the console.

The second conditional statement assigns the value true to b2 and then checks if b1 is also true. Since both conditions are true, the code executes the third print statement, printing "3" to the console.

Therefore, the output of the program is:

2 3

So, the correct answer is:

The Answer is: B

Multiple choice technology web technology
  1. compiletime error at lines 1,2,3,4,5

  2. compiletime error at lines 2,3,4,5

  3. compiletime error at lines 2,3,4

  4. No error

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

In Java, local variables (like 'int i' at line 1) cannot have access modifiers (private, protected, public). These modifiers can only be applied to class members (fields, methods, classes). Lines 2, 3, 4 attempt to declare private/protected/public fields inside a method, which is illegal. Line 5 tries to access these non-existent fields. The instance variable 'int i' at class level is shadowed by the local 'int i' in main().

Multiple choice technology programming languages
  1. compiletime error at lines 1,2,3,4

  2. compiletime error at line 3

  3. compiletime error at line 1

  4. compiletime error at lines 3,4

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

In Java, interface methods are implicitly public. Declaring a method as protected (line 3) is always illegal. Prior to Java 9, private methods (line 4) were also illegal, and even in newer versions, only private or public modifiers are permitted. Thus, lines 3 and 4 produce compilation errors.

Multiple choice technology programming languages
  1. Run Time Exception

  2. Compile Error

  3. the code compile and runs fail

  4. None of the above

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

In Java, calling start() on a Thread twice throws IllegalThreadStateException at runtime because a thread cannot be restarted once it has terminated. The start() method checks the thread state and throws an exception if the thread was already started.

Multiple choice technology programming languages
  1. The element will be successfully added

  2. ArrayIndexOutOfBounds Exception

  3. The Vector allocates space to accommodate up to 15 elements

  4. None of the above

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

Vector(5,10) creates a Vector with initial capacity 5 and capacity increment 10. Adding a 6th element succeeds (Vector automatically grows) and capacity becomes 15 (5+10). Options B and D are incorrect.

Multiple choice technology programming languages
  1. No output

  2. 3 and 5

  3. 1, 3 and 5

  4. 3

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

Since x is 2, execution jumps to case 2:. Because there are no break statements, execution falls through to case 3: (printing "3?") and then falls through to case 5: (printing "5?"). Therefore, the output displays both "3" and "5" (with question marks, as written in the print statements).