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. .faza

  2. .fzba

  3. ..azba

  4. .fazba

  5. ..fezba

  6. Compilation fails

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

The StringBuffer starts as '..fedcba'. delete(3,6) removes indices 3-5 ('fed'), leaving '..cba'. insert(3,'az') inserts at position 3, giving '..azcba'. Since length is 6 (not >6), x stays 4. delete(1,2) removes the '.' at index 1, yielding '.azba'. Option C is correct.

Multiple choice technology databases
  1. It will print the value of divide operation

  2. When others exception will be executed as we can't concatenate number with a string in dbms_output statement directlt. We have to use to_char to convert it as varchar2

  3. WHEN ZERO_DIVIDE will be executed

  4. When others exception will be executed as pe_ratio is not initialized.

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

Dividing by zero raises the predefined ZERO_DIVIDE exception, which is caught by the first WHEN clause. The program prints the custom message from that handler and sets pe_ratio to NULL. Therefore the option stating that ZERO_DIVIDE will be executed is correct, matching the stored answer.

Multiple choice technology databases
  1. There is no error in the statement

  2. Exception handler is missing

  3. DBMS_OUTPUT.PUT_LINE package must be declared

  4. semicolon is missing in the line "Dbms_output.put_line(‘Hello world’)"

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

In PL/SQL each statement must end with a semicolon. The line Dbms_output.put_line('Hello world') lacks this terminating semicolon, causing a compilation error. The stored answer correctly identifies this omission.

Multiple choice technology programming languages
  1. Compile failure

  2. sucessfully compiled, but through exception in run time

  3. It runs sucessfuly and prints "without the main method"

  4. It runs sucessfuly, but No output.

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

Java allows code execution without a main method using static initializers. The static block runs when the class is loaded, prints the message, and System.exit(0) terminates the JVM before it looks for main. This is valid Java syntax and executes successfully.

Multiple choice technology programming languages
  1. compiletime error at lines 3,4,5

  2. compiltime error at line 4,5

  3. compiletime error at line 3

  4. Runtime Exception

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

Line 3 has valid syntax (though unusual). Line 4 is invalid - array declaration syntax is type[] arrayName not type arrayName[size]. Line 5 is invalid - you can't declare array dimensions in the declaration without initialization. The compiler errors on lines 4 and 5.

Multiple choice technology programming languages
  1. prints object created

  2. Compile time error

  3. Runtime Excepion

  4. None of the above

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

This code is valid Java. A static interface can contain static member classes, and C1.I.C2 refers to that nested class. The object creation using new C1.I.C2() is valid syntax, and the program compiles and runs successfully, printing 'object created'.

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

  2. Prints: 1,0

  3. Prints: 0,1

  4. Compile-time error

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

In i = i++ + f1(i), the post-increment operator i++ returns the current value (0) then increments i to 1. So f1 receives 0, prints '0,', and returns 0. The expression becomes i = 0 + 0 = 0, but wait - after i++ executes, i becomes 1. So the right side evaluates to 0+0=0, then i (which is 1 from the increment) is assigned 0. Actually, let me trace more carefully: i starts at 0. i++ returns 0, then i becomes 1. f1(i) where i=1 now is called... but the parameter is evaluated before the increment? No, parameters are evaluated left to right. So f1 receives 0, prints '0,'. The expression is 0 + 0 = 0. i is set to 0. But the post-increment made i=1 temporarily, but then the assignment overwrites it. Output: '0,0'. Wait, option B says '1,0'. Let me reconsider. Actually Java evaluates i++ first (returns 0, i becomes 1), then evaluates f1(i) - but what's i at this point? It's 1. So f1(1) prints '1,' and returns 0. Then 0+0=0. Output: '1,0'.

Multiple choice technology programming languages
  1. compile time error

  2. Runtim error

  3. prints 8

  4. prints 0

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

The variable i2 is only assigned inside the if block, but it's declared outside. Java requires local variables to be definitely assigned before use. If i1 were less than or equal to 3, i2 would be uninitialized when println is called. This is a compile-time error.

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

  2. compile time error at line 2

  3. the code compiles fine

  4. none of the above

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

An interface in Java can contain inner classes, which are implicitly public and static. The syntax in the snippet is fully valid, so the code compiles successfully.

Multiple choice technology programming languages
  1. Compile failure

  2. sucessfully compiled, but through exception in run time.

  3. It runs sucessfuly and prints "without the main method"

  4. It runs sucessfuly, but No output.

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

This is nearly identical to question 141060. The class name is now 'withoutmain' instead of 'WithoutMain' (capital W), but the class is still public. Java allows public classes. The static block executes when the class loads, prints the message, and System.exit(0) terminates before main is required. The program compiles and runs successfully.

Multiple choice technology programming languages
  1. compiletime error at lines 3,4,5

  2. compiltime error at line 4,5

  3. compiletime error at line 3

  4. Runtime Exception

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

In Java, array declarations cannot specify the array size on the left side of the assignment. Lines 4 and 5 violate this rule, causing compile-time errors. Line 3 is valid 2D array syntax.

Multiple choice technology programming languages
  1. prints object created

  2. Compile time error

  3. Runtime Excepion

  4. None of the above

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

In Java, interfaces can contain nested classes, which are implicitly static and public. The syntax for declaring and instantiating C1.I.C2 is correct, so it compiles and runs without issue.

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

  2. Prints: 1,0

  3. Prints: 0,1

  4. Compile-time error

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

Java evaluates expressions left-to-right. i++ returns 0 then increments i to 1. f1(i) is called with i=1, prints '1,' and returns 0. So i = 0 + 0 = 0. The post-increment result (0) is assigned to i, overwriting the increment. Output: 1,0

Multiple choice technology programming languages
  1. will cause a compiler error as the range of character is between 0 and 2^16 - 1. Will request for an explicit cast.

  2. will not cause a compiler error and c will have the value -1;

  3. c will not represent any ASCII character.

  4. c will still be a Unicode character.

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

In Java, char is an unsigned 16-bit type with range 0 to 65535. Assigning -1 requires an explicit cast because -1 is outside this range. Without casting, the compiler will reject the assignment.

Multiple choice technology programming languages
  1. compiletime error at lines 3,4,5

  2. compiltime error at line 4,5

  3. compiletime error at line 3

  4. Runtime Exception

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

Line 4 fails because C-style array initialization with size is invalid: 'int a2[4]={3,4,5,6};' - Java doesn't allow specifying size when initializing. Line 5 fails because 'a2' is already declared at line 4. Line 3 is valid syntax (though odd) - it declares a 2D array. The claimed answer is correct.