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. 57 22

  2. 45 38

  3. 45 57

  4. An exception occurs at runtime.

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

The code creates an anonymous subclass of AbstractTest overriding getNum() to return 22. It then instantiates an anonymous subclass of inner class Bar, overriding getNum() to return 57. Evaluating f.getNum() + " " + t.getNum() outputs '57 22'.

Multiple choice technology programming languages
  1. Compilation fails.

  2. An error occurs at runtime.

  3. It prints "foobarhi"

  4. It prints "barhi"

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

When Foo() is called, its constructor prints 'foo'. In makeBar(), new Bar(){} creates an anonymous subclass of Bar, so Bar's constructor runs first (prints 'bar'), then go() is called (prints 'hi'). The output is 'foobarhi'. Option A is wrong because the code compiles successfully. Option B is wrong because no runtime error occurs. Option D incorrectly omits the 'foo' printed by the Foo constructor.

Multiple choice technology programming languages
  1. if((i == 0) || (j/i == 1))

  2. if((i == 0) | (j/i == 1))

  3. if((i != 0) && (j/i == 1))

  4. if((i != 0) & (j/i == 1))

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

Option B uses bitwise OR (|) which evaluates both operands regardless of the first value. Since i=0, j/i causes division by zero (ArithmeticException). Option D uses bitwise AND (&) which also evaluates both operands, so j/i executes and throws ArithmeticException. Options A and C use short-circuit operators (||, &&) where the second operand is skipped when the result is determined by the first operand, preventing the exception.

Multiple choice technology programming languages
  1. result = 1

  2. result = 10

  3. result = 11

  4. result = 11010

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

Line 13: x and y are different Long objects, so == returns false (result stays 0). Line 15: x.equals(y) returns true because both are Long objects with value 42 (result=10). Line 17: x.equals(z) returns false - Long equals only returns true for other Long objects, not Short. Line 19: x.equals(x2) returns false - x2 is Short, not Long. Line 21: x.equals(z2) returns false - z2 is Integer, not Long. Final result is 10.

Multiple choice technology programming languages
  1. Error

  2. 98

  3. 88

  4. 16

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

parseInt() parses integers from strings, stopping at the first non-numeric character. parseInt("8.56") returns 8 (stops at the decimal). parseInt("8error") also returns 8 (stops at 'e'). The alert concatenates these with a space: "8 " + " " + "8" = "8 8". Note: The code has extra spaces that may affect output formatting, but the numeric values are definitely 8 and 8.

Multiple choice technology programming languages
  1. 9

  2. 8

  3. 10

  4. error

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

JavaScript Date months are zero-indexed (January = 0, February = 1, etc.). September is the 9th month, so getMonth() returns 8. The code creates a Date object for September 30, 2011, and getMonth() correctly returns 8 for September. Option A (9) incorrectly assumes 1-based indexing.

Multiple choice technology programming languages
  1. Davin

  2. Jerome

  3. error

  4. lastname

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

The code creates an object using literal notation with firstname='Jerome' and lastname='Davin', then alerts personObj.lastname which outputs 'Davin'. Object literal syntax is a cleaner way to create objects compared to the Object constructor.

Multiple choice technology programming languages
  1. sop 1

  2. sop 2

  3. sop 3

  4. sop 4

  5. compilation fails

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

To solve this question, we need to understand the methods used in the given Java code. TreeMap is a class that implements the Map interface using a tree structure. It stores key-value pairs in a sorted order. The methods used in the given code are:

  • higherKey(Object key): Returns the least key strictly greater than the given key, or null if there is no such key.
  • ceilingKey(Object key): Returns the least key greater than or equal to the given key, or null if there is no such key.
  • floorKey(Object key): Returns the greatest key less than or equal to the given key, or null if there is no such key.
  • tailMap(K fromKey): Returns a view of the portion of this map whose keys are greater than or equal to fromKey.

Now, let's go through each option and determine which one will produce the output "1st after mango: p":

A. sop 1: This statement calls the higherKey() method on the TreeMap object with the argument "f". This returns the least key strictly greater than "f", which is "p". The output of this statement will be "1st after mango: p". Therefore, option A is correct.

B. sop 2: This statement calls the ceilingKey() method on the TreeMap object with the argument "f". This returns the least key greater than or equal to "f", which is "f" itself. The output of this statement will be "1st after mango: f". Therefore, option B is incorrect.

C. sop 3: This statement calls the floorKey() method on the TreeMap object with the argument "f". This returns the greatest key less than or equal to "f", which is "f" itself. The output of this statement will be "1st after mango: f". Therefore, option C is incorrect.

D. sop 4: This statement creates a new TreeMap object named sub using the tailMap() method on the existing TreeMap object myMap. The tailMap() method returns a view of the portion of this map whose keys are greater than or equal to "f". The sub.firstKey() method returns the first key in the sub map, which is "f". The output of this statement will be "1st after mango: f". Therefore, option D is incorrect.

E. compilation fails: There are no compilation errors in the given code. Therefore, option E is incorrect.

The Answer is: A. sop 1

Multiple choice technology programming languages
  1. .e1

  2. .e2

  3. =s

  4. fly

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

This code tests several comparison behaviors. x.equals(L343) returns false because Integer.equals() returns false when comparing with different types (Integer vs Long). x.equals(343) returns true (Integer equals int) → adds '.e2'. Short division (343/49=7) with unboxing gives s1=7, so s1==7 is true → adds '=s'. s1 < new Integer(8) compares primitive Short 7 with Integer 8, which unboxes to 7<8 (true) → adds 'fly'. Final output: '-.e2 =s fly' (the 4th concatenation adds leading space).