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. x = 1

  2. x = 3

  3. Compilation fails.

  4. An exception is thrown at runtime.

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

The code in line 13 uses assignment (=) instead of equality comparison (==). In Java, the if condition requires a boolean expression, but x = y results in an integer value, which cannot be converted to boolean. This causes a compilation error.

Multiple choice technology programming languages
  1. Compilation fails because of an error in line 2 of class Test2.

  2. x = 42

  3. Compilation fails because of an error in line 3 of class Test1.

  4. Compilation fails because of an error in line 4 of class Test2.

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

The compilation fails in Test2 (line 2) because the class extends 'test1.Test1' but this package reference is not imported. To use a class from another package, you need to import it first: 'import test1.Test1;'. Line 2 of Test2 is where Test1 is referenced without an import statement.

Multiple choice technology programming languages
  1. ABDCBDCB

  2. ABCDABCD

  3. Compilation fails.

  4. An exception is thrown at runtime.

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

First, the loop initialization runs foo('A') (prints A). In the first check, foo('B') (prints B) and i<2 are true; loop body increments i and runs foo('D') (prints D); then update runs foo('C') (prints C). This repeats until the third check where i<2 is false, terminating after printing B.

Multiple choice technology programming languages
  1. Table One and Table Two X Y X Z ------------ 1 2 2 5 1 2 3 6 1 2 4 9 2 3 2 5 2 3 3 6 2 3 4 9

  2. Table One and Table Two X Y X Z ------------ 1 2 2 5 2 3 2 5

  3. Table One and Table Two X Y Z ------------ 1 2 5 2 3 5

  4. Table One and Table Two X Y Z ------------ 1 2 . 2 3 5

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

The query performs a Cartesian product (cross join) of tables ONE and TWO because no WHERE clause joins them. Table ONE has 2 rows (X=1,Y=2 and X=2,Y=3) and Table TWO has 3 rows (X=2,Z=5, X=3,Z=6, X=4,Z=9). The result is 2 × 3 = 6 rows, combining each row from ONE with each row from TWO. Option A shows all 6 rows correctly.

Multiple choice technology web technology
  1. True

  2. False

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

Both CODE 1 and CODE 2 perform an inner join between tables sql.oilprod and sql.oilrsrvs on the country column. CODE 1 uses the older comma-separated tables syntax with WHERE clause for joining, while CODE 2 uses the explicit INNER JOIN syntax with ON clause. Both produce identical results - they are equivalent SQL statements.

Multiple choice technology programming languages
  1. One and Two Joined One b Two b ------------------- a 1 a 1 b 2 b 2 d 4 d 4 c . e . c . f .

  2. One and Two Joined One b Two b ------------------- a 1 a 1 b 2 b 2 c . c . d 4 d 4 c . e . c . f .

  3. One and Two Joined One b Two b ------------------- a 1 a 1 b 2 b 2 c . c . d 4 d 4

  4. One and Two Joined One b Two b ------------------- a 1 a 1 b 2 b 2 . . . . d 4 d 4

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

The query performs an inner join on column b between tables ONE and TWO. Matching rows: both have (a,1), (b,2), (c,.) with NULL/SAS missing values. The row (d,4) appears in both tables. Row (e,.) and (f,.) in table TWO don't have matches in ONE. The inner join returns all matched rows including NULL matches on the join column. Option B correctly shows all 6 matched rows.

Multiple choice technology programming languages
  1. Table JOINED Flight Supervisor Flight Destination ------------------------------------------- 145 Kang 145 Brussels 145 Kang 145 Edmonton 145 Ramirez 145 Brussels 145 Ramirez 145 Edmonton 150 Miller 150 Paris 150 Miller 150 Madrid 150 Picard 150 Paris 150

  2. Table JOINED Flight Supervisor Flight Destination ------------------------------------------- 145 Ramirez 145 Edmonton 150 Picard 150 Madrid

  3. Table JOINED Flight Supervisor Flight Destination ------------------------------------------- 145 Kang 145 Brussels 145 Kang 145 Edmonton 150 Miller 150 Paris 150 Miller 150 Madrid

  4. Table JOINED Flight Supervisor Flight Destination ------------------------------------------- 145 Kang 145 Brussels 145 Ramirez 145 Brussels 150 Miller 150 Paris 150 Picard 150 Paris 150 Picard 150 Madrid

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

The SQL query performs an inner join between fltsuper and fltdest on Flight. Flight 145 appears twice in both tables (2×2=4 combinations), Flight 150 appears twice in both tables (2×2=4 combinations). The other flights (155, 157 in fltsuper; 165 in fltdest) have no matches and are excluded from the inner join result. The output has 8 rows total. Option A correctly shows the pattern, though it appears truncated at the end.

Multiple choice technology programming languages
  1. proc sql; update work.frequentflyers set pointsearned=pointsearned* case if milestraveled < 10000 then 1.5 if milestraveled >= 10000 then 2 else 1 end;

  2. proc sql; update work.frequentflyers set pointsearned=pointsearned* case when milestraveled < 10000 then 1.5 when milestraveled >= 10000 then 2 else 1 end;

  3. proc sql; update work.frequentflyers set pointsearned=pointsearned* case if milestraveled < 10000 then pointsearned*1.5 if milestraveled >= 10000 then pointsearned*2 else 1 end;

  4. proc sql; update work.frequentflyers set pointsearned=pointsearned* case if milestraveled < 10000 then pointsearned*1.5 if milestraveled >= 10000 then pointsearned*2 else pointsearned*1 end;

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

Option B correctly uses CASE with WHEN clauses (not IF) and multiplies pointsearned by the appropriate factor (1.5 for <10000 miles, 2 for >=10000 miles). Options A, C, and D incorrectly use IF instead of WHEN in the CASE statement syntax. Options C and D also incorrectly reference pointsearned again inside the CASE expression, which would cause double multiplication.

Multiple choice technology platforms and products
  1. final String abc = "Neeraj"; abc = "Rathi";

  2. final String abc;abc = "Rathi";

  3. final ArrayList al = new ArrayList();al.add("Neeraj");al.add("Rathi");

  4. final int i; i = 0;

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

A final variable can only be assigned once. In option A, abc is declared final and initialized with 'Neeraj', then reassigned to 'Rathi' - this is illegal. Options B and D are legal blank finals (declared final, assigned once later). Option C works because the reference is final, not the contents - you can modify the list but not reassign al.

Multiple choice technology programming languages
  1. OF(11) is: 45

  2. OF(11) is: 56

  3. Compilation fails.

  4. Runtime Exception

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

The code contains a syntax error on the else clause. The statement 'else (x <= 4)' is invalid Java syntax - an else statement cannot have a condition. It should be 'else if (x <= 4)' for conditional execution. This causes the code to fail compilation.

Multiple choice technology programming languages
  1. -f and java.ArrayIndexOutOfBoundsException

  2. -f

  3. ArrayIndexOutOfBoundsException

  4. None of these.

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

When 'java Demo' is run with no command-line arguments, args[0] throws ArrayIndexOutOfBoundsException immediately. This is caught by the catch(Exception x) block, setting s='b'. The finally block executes regardless, appending 'f' to s. The output is '-f' followed by the ArrayIndexOutOfBoundsException being printed (since it wasn't caught specifically). The initial try block's 't' is never reached.

Multiple choice technology programming languages
  1. int y = x;

  2. int y = 10;

  3. int y = 11;

  4. None of the above will allow compilation to succeed.

  5. int y = 12;

  6. int y = 13;

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

The do-while loop executes the body first, then checks the condition x++ < y. With y=11 and x starting at 0: x increments to 1 and 1<11 is true (loop continues). This continues until x becomes 11: x increments to 12 and 12<11 is false (loop exits). At exit, x=12, which is printed. Each iteration increments x after the comparison.

Multiple choice technology programming languages
  1. -

  2. -c

  3. -c2

  4. -2c

  5. -c22b

  6. Compilation fails.

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

method1 calls method2, which calls method3 (first call). method3 throws Exception immediately. This exception propagates to method1's catch block, appending 'c' to s. The code 's += 2' and everything after in method2 never executes (unreachable after exception). The initial s='-' becomes '-c'.

Multiple choice technology programming languages
  1. -c

  2. -X

  3. -cm

  4. -cmp

  5. -cmXp

  6. Compilation fails.

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

The switch statement has no break statements, causing fall-through. With TimeZone.CST: case CST matches, appends 'c'. No break, so falls through to case MST, appends 'm'. No break, falls through to default, appends 'X'. No break, falls through to PST, appends 'p'. The final string is '-cmXp'. Fall-through continues through all cases after the match.

Multiple choice technology programming languages
  1. 8

  2. 8 7

  3. 8 7 6

  4. Compilation fails.

  5. An exception is thrown at runtime.

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

The code fails to compile for multiple reasons. First, there is a syntax error in the print statement, which ends with a closing brace instead of a parenthesis. Second, the continue statement attempts to target an if statement label instead of a loop, which is illegal in Java.