Computer Knowledge

Programming Output Evaluation

1,721 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. I am in Constructor p = 10

  2. I am in Constructor p = 0

  3. Compiler Error

  4. Exception

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

The parameterized constructor correctly calls this() as its first statement, executing the no-arg constructor first. It prints 'I am in Constructor', then assigns p and prints 'p = 10'. The output is the concatenation of both print statements.

Multiple choice technology programming languages
  1. Message Hello

  2. I am in Constructor

  3. Compiler Error

  4. Exception

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

The class has two overloaded main methods - one with String[] args and one with String args. When the JVM launches, it calls the standard main(String[] args) which invokes the no-arg constructor, printing 'I am in Constructor'. The second main method is never called.

Multiple choice technology web technology
  1. ab

  2. abcd

  3. ab cd

  4. a b c D

  5. Compilation fails

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

The variable s is declared inside the try block but used in the while condition. However, s is not properly initialized or assigned before use. More critically, br.flush() is called on BufferedReader which doesn't have a flush() method - only the underlying Writer does. This causes compilation failure.

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 creates a 2D table using nested loops, so table must be a List of List. Option B correctly declares List> table = new ArrayList>() - ArrayList implements List, and the generic type matches. Option A fails because List is an interface and cannot be instantiated. Option C fails because ArrayList> cannot be assigned to List> - the inner generic type must match exactly. Options D-F use invalid syntax with commas instead of proper generic notation.

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 &amp;&amp; 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 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 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 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.