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. Compile with error

  2. 10

  3. 12

  4. Runtime Exception

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

All variables declared inside interfaces are implicitly public, static, and final. Attempting to reassign a value to TestInf.i (TestInf.i = 12) causes a compile-time error because it is a constant.

Multiple choice technology programming languages
  1. Compile with error

  2. 5

  3. 0

  4. Runtime Exception

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

The variable 'a' is defined inside a static initialization block, making its scope local to that block. Attempting to access 'a' in the main method causes a compilation error because it is unresolved.

Multiple choice technology programming languages
  1. r1 r4 pre b1 b2 r3 r2 post

  2. r1 r4 pre b1 b2 post

  3. r1 r4 pre b1 b2 post r3 r2

  4. pre r1 r4 b1 b2 r2 r3 post

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

To understand the output of the given code, the user needs to know about the order of initialization of static and non-static blocks, constructors, and the concept of inheritance.

When the main method is executed, the following sequence of events will occur:

  1. The static block of class B will be executed first. It will print "r1 r4".

  2. The static block of class C will not be executed because it is not defined.

  3. The print statement inside the main method will execute and print "pre".

  4. A new object of class C is created using the default constructor.

  5. Since class C extends class B, the constructor of class B will be called first.

  6. Before the constructor of class B is called, the non-static block of class A will be executed. It will print "b1".

  7. The constructor of class B will be executed next. It will print "b2" and "r2".

  8. Before the constructor of class C is called, the non-static block of class B will be executed. It will print "r3".

  9. The constructor of class C will be executed last. It will not print anything.

  10. After the constructor of class C is called, the print statement inside the main method will execute and print "post".

Therefore, the output will be:

The Answer is: A) r1 r4 pre b1 b2 r3 r2 post

Multiple choice technology programming languages
  1. true

  2. false

  3. Compile Error

  4. Runtime Exception

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

The code prints true because Integer.equals(Object) performs value comparison after auto-boxing the primitive int 34 to an Integer wrapper, and their primitive integer values are equal.

Multiple choice technology programming languages
  1. one

  2. two

  3. Compile error - char can't be permitted in switch statement

  4. Compile error - Illegal modifier for the class Test; only public, abstract & final are permitted

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

The code has a compilation error: 'static' is not a valid modifier for a top-level class in Java - only public, abstract, and final are permitted. Option C is incorrect because chars ARE allowed in switch statements. Options A and B are irrelevant since compilation fails. The question tests Java class declaration rules.

Multiple choice technology programming languages
  1. 1 2 3

  2. Compile error , can't add primitive type in ArrayList

  3. Compile error on for(int i:list) , Incorrect Syntax

  4. 0 0 0

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

Java autoboxing automatically converts primitive int values to Integer objects when adding to ArrayList. The enhanced for loop iterates through each element and prints it on a separate line. Options B and C are incorrect because autoboxing and the for-each syntax are both valid in Java.

Multiple choice technology programming languages
  1. Prints out: Exception Finally

  2. Prints out: Finally

  3. Prints out: Exception

  4. Compile with error

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

When dividing 0 by 3, the result is 0 (no exception occurs because the denominator is non-zero). The try block completes successfully, so the catch block is skipped. The finally block always executes regardless of whether an exception occurred, printing 'Finally'.

Multiple choice technology programming languages
  1. 0

  2. Compile with error

  3. null

  4. NullPointerException

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

Attempting to unbox a null Integer reference to a primitive int throws a NullPointerException. This happens at runtime during the assignment 'int j = i' because Java cannot convert null to a primitive value. Option A is incorrect (null doesn't become 0), and B is wrong because this compiles fine but crashes at runtime.

Multiple choice technology programming languages
  1. NullPointerException

  2. It works properly

  3. Compile Error : No readPassword() method in Console class

  4. null

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

The code has an infinite loop: auth is never set to true, so the condition (!auth && ++count < 3) will keep running until count reaches 3. The readLine() call with null argument will throw NullPointerException. The code demonstrates incorrect Console API usage and a logic bug. Option A is correct - NullPointerException occurs.

Multiple choice technology programming languages
  1. compile time error at line 1

  2. compile time error at line 2

  3. compile time error at line 3

  4. prints 9

  5. Runtime exception

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

In Java, an interface can define a nested class, which is implicitly public and static. A final nested class is legal, and defining a static member inside it is also valid. The code compiles without issues and successfully prints 9.

Multiple choice technology programming languages
  1. Prints: false,false

  2. Prints: true,false

  3. Prints: false,true

  4. Prints: true,true

  5. None of the above

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

StringBuffer's equals() method compares object references (inherited from Object), not content. So sb2.equals(s1) returns false because they're different objects. String's equals() compares content, but it only returns true when comparing with another String, so s1.equals(sb2) returns false. Output is false,false. Option A is correct.

Multiple choice technology programming languages
  1. (A), (B), (D) & (E)

  2. (B), (C) & (D)

  3. (B), (D), (E) & (F)

  4. (B), (D) & (E)

  5. (D) & (F)

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

In Java, arithmetic operations on byte values are promoted to int. The expression b1 * b2 (5 * 10 = 50) produces an int result. This int can be assigned to int, long, float, or double through widening conversions. It cannot be assigned directly to byte or short without explicit casting.

Multiple choice technology programming languages
  1. error

  2. 5

  3. garbage number

  4. 3

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

In Python, negative indexing access elements from the end of the list. The index -1 retrieves the last element, which is 5. It does not produce an error or return a garbage value.

Multiple choice technology programming languages
  1. Bic

  2. ic

  3. icy

  4. error: no method matching substring(int,char)

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

The substring method in Java extracts characters from index begin (inclusive) to end (exclusive). With s='Bicycle', begin=1, end=3, it extracts characters at positions 1 and 2, which are 'i' and 'c', resulting in 'ic'. Note that iEnd is char but gets promoted to int.

Multiple choice technology programming languages
  1. 0

  2. 1

  3. 2

  4. 3

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

Due to short-circuit evaluation, the first expression (t && ((i++) == 0)) executes i++ making i=1. The second expression (f && ((i+=2) > 0)) short-circuits because f is false, so i+=2 never executes. Final i=1.