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. The program does not compile because statement "test = test + test" is illegal.

  2. The program prints "abc"

  3. The program prints "abcabc"

  4. The class does not compile because the top level class cannot be protected.

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

Java outer classes cannot be declared with the protected access modifier; they can only be public or package-private. This access modifier violation prevents compilation, making details like string concatenation irrelevant.

Multiple choice technology programming languages
  1. tomcat

  2. root

  3. Compile time Error

  4. Run Time Error

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

Java requires the condition in an if statement to evaluate to a boolean. The expression 'a=10' is an assignment that returns the integer value 10, resulting in a compile-time type mismatch error instead of evaluating to a truth value.

Multiple choice technology programming languages
  1. Compile time error

  2. false true

  3. true false

  4. true true

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

The == operator compares object references in Java, returning false because s1 (heap object) and s2 (string literal) are different objects. The equals() method compares string contents, returning true because both contain 'TCS'. This is a fundamental Java concept distinguishing reference equality from value equality.

Multiple choice technology programming languages
  1. true true

  2. true false

  3. false true

  4. Exception

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

When s2 = s1 assigns the reference, both variables point to the same String object in memory. The == operator returns true because they're the same reference. The equals() method also returns true because String's implementation compares content, which is identical.

Multiple choice technology programming languages
  1. true false

  2. false true

  3. Compile Error

  4. false false

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

This code fails to compile because StringBuilder cannot be initialized with a String literal using the = operator. StringBuilder s1 = 'TCS' is a type mismatch - StringBuilder requires explicit construction via new StringBuilder(). The code won't reach runtime.

Multiple choice technology programming languages
  1. false true

  2. false false

  3. true false

  4. true true

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

new StringBuilder() creates two distinct objects, so == returns false (different references). StringBuilder does NOT override equals() - it inherits Object's default implementation which also checks reference equality. Therefore equals() returns false too, unlike String which compares content.

Multiple choice technology programming languages
  1. false true

  2. false false

  3. true true

  4. true false

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

After s2 = s1, both variables reference the exact same StringBuilder object. The == operator returns true (same reference). StringBuilder's equals() method (inherited from Object) also returns true because it compares references, which are now identical.

Multiple choice technology programming languages
  1. 10,13

  2. 10,14

  3. 14,14

  4. Syntax error

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

The ABAP code contains multiple syntax errors. First, 'statics' should be 'STATICS'. Second, there's a name mismatch: the PERFORM statement calls 'add' (lowercase) but the FORM definition is named 'ADD' (uppercase). ABAP is case-sensitive for FORM/PERFORM names. Additionally, the STATICS declaration syntax is incorrect. These errors would prevent compilation.

Multiple choice technology programming languages
  1. default

  2. default, zero, one

  3. Compiler error

  4. No output displayed

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

The switch expression evaluates to i = 3. Since no case matches 3, the execution jumps to the default label. Because there is no break statement after the default, case 0, and case 1 statements, execution falls through all of them until a break is encountered in case 1, printing 'default', 'zero', and 'one'.

Multiple choice technology web technology
  1. -2^15 to 2^15-1

  2. -2^7 to 2^7-1

  3. -2^31 to 2^31-1

  4. 0 to 2^16-1

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

Java's char primitive type is a 16-bit unsigned integer representing UTF-16 code units, ranging from 0 (null character) to 65535 (2^16-1). Unlike other integral types (byte, short, int), char is unsigned and cannot represent negative values. Option A describes short, B describes byte, and C describes int.

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

Java automatically promotes the smaller primitive type to match the larger type during comparison operations. This is part of binary numeric promotion - for example, an int compared to a long is promoted to long, a float compared to a double is promoted to double. This promotion happens automatically without requiring explicit casting from the programmer.

Multiple choice technology programming languages
  1. s = tcs In finally

  2. Compiler Error

  3. Exception

  4. s = tcs

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

The trimString() method calls x.trim() which removes leading/trailing whitespace. On input ' tcs ', this returns 'tcs'. The finally block always executes, so output is 's = tcs' followed by 'In finally'. No exception occurs, so flow is normal.

Multiple choice technology programming languages
  1. s = tcs Exception

  2. s = tcs Null Pointer Exception

  3. Exception

  4. Compiler Error

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

This code produces a compiler error because the catch block order is invalid. Exception is a superclass of NullPointerException, so catching Exception first makes the NullPointerException catch unreachable. More specific exceptions must be caught before their parent types.

Multiple choice technology programming languages
  1. p = 2.0

  2. Compiler Error

  3. Exception

  4. p = 2.0 In finally

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

The division 10 / 5 returns 2.0 (as double). Since no exception occurs, the catch block is bypassed. However, the finally block is guaranteed to execute regardless of whether an exception is thrown, appending 'In finally' to the output. Thus, the program prints both lines sequentially.