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 web technology
  1. 132

  2. Exception arises

  3. 4

  4. 13

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

In Java, when the + operator is used with a String and any other type, Java performs string concatenation. The integer 3 is converted to its string representation "3" and concatenated with "1", resulting in "13". This is a fundamental Java behavior - the + operator is overloaded for both arithmetic addition and string concatenation. Option A is incorrect (would require different order), Option B is wrong (no exception), Option C would only result from arithmetic addition of integers.

Multiple choice technology programming languages
  1. It will print -10

  2. It will result in Assertion Error showing the message -"The value must not be negative".

  3. The code will not compile.

  4. None of these.

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

The Java assertion statement syntax requires the second expression (after the colon) to return a value. Because methodB() has a void return type, it cannot be used as the detail message expression, causing a compilation error.

Multiple choice technology programming languages
  1. Prints : "I am false interface" followed by " I am false String"

  2. Prints : "I am true interface" followed by " I am true String"

  3. Prints : "I am true interface" followed by " I am false String"

  4. Compile-time error

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

The instanceof operator checks if an object is an instance of a specific type or interface. MyInstanceTest implements MyInterface, so 't instanceof MyInterface' returns true (prints 'I am true interface'). The static variable 's' is null (default value), and 'null instanceof String' returns false (prints 'I am false String'). The instanceof operator safely handles null values by returning false instead of throwing an exception.

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

The ternary operator expression ((a < 5) ? 9.9 : 9) involves type promotion. Since the second operand (9.9) is a double, the third operand (9) is promoted to double, and the result is 9.0 (not 9). The output is 'Value is - 9.0', which doesn't match option A (9), B (5), or C (compilation error). Therefore D (None of these) is correct. This tests understanding of numeric promotion in ternary expressions.

Multiple choice technology programming languages
  1. Prints : MyThread: start() followed by MyRunnable:run()

  2. Prints : MyThread: run() followed by MyRunnable:start()

  3. Prints : MyThread: start() followed by MyRunnable:start()

  4. Compile time error

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

myThread overrides start(), so calling myThread.start() executes its custom method, printing 'MyThread: start()'. thread is initialized with myRunnable, so calling thread.start() executes myRunnable.run(), printing 'MyRunnable: run()'.

Multiple choice technology programming languages
  1. Compile-time error

  2. prints : 3

  3. prints : 1

  4. prints : 7

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

Initially, static variable x is 0. x-- decrements it to -1. In myMethod(), y = x++ + ++x evaluates as -1 + 1 = 0, leaving x at 1. Back in main, x + y + ++x evaluates to 1 + 0 + 2 = 3.

Multiple choice technology programming languages
  1. 15 0 20

  2. 15 0 15

  3. 20 0 20

  4. 0 15 20

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

Java passes object references by value. In second(), the local parameter 'v' is reassigned to a new Value object (v = val), which doesn't affect the original reference in first(). However, before reassignment, v.i = 20 modifies the object's field through the original reference. The second() method prints '15 0' (val.i=15, local i=0). Back in first(), v.i is 20 (modified by second() before reassignment), so it prints '20'. Final output: '15 0 20'. The reassignment in second() doesn't affect first()'s reference.

Multiple choice technology programming languages
  1. 300

  2. 240

  3. 120

  4. Compilation error

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

The code compiles and runs successfully. myChi.addMe(10, 20, 30) returns 10 + 10 + 20 + 20 + 30 + 30 = 120. myChi.addMe(myChi) calls addMe(10, 20, 30) on itself, returning 120. myPar.addMe(myPar) returns 10 + 10 + 20 + 20 = 60. The sum is 120 + 120 + 60 = 300.

Multiple choice technology programming languages
  1. The code won't compile

  2. "Some things are true in this world" will be printed

  3. "Hey this won't compile" will be printed

  4. None of these

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

The nested if structure is: if(a) { if(b) { if(c) {...} else {...} } else if(a && (b=c)) {...} else {...} }. With a=true, b=false, c=true: The outer if(a==true) succeeds. Inside, if(b==true) fails (b is false), so we go to else if(a && (b=c)). Here, (b=c) assigns c to b, making b=true, so the condition (true && true) is true, printing "It's too confusing to tell what is true and what is false". This output is not listed in options A, B, or C, so D is correct.

Multiple choice technology programming languages
  1. Same

  2. Equals

  3. The code compiles, but nothing is displayed upon execution.

  4. The code fails to compile

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

The code creates two separate String objects using 'new String("Test")'. The == operator compares object references, which are different for distinct objects, so s1==s2 is false. The equals() method compares string content, and both strings contain 'Test', so s1.equals(s2) is true. The code prints only 'Equals'. This tests the fundamental distinction between reference equality (==) and content equality (equals()).