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

  2. -c

  3. -c2

  4. -2c

  5. -c22b

  6. -2c2b

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

To solve this question, we need to trace the execution of the code and see how the value of the variable s changes.

Starting with the main method, it creates a new instance of the Plane class and calls its method s1().

In the s1() method, it calls the method sl().

In the sl() method, it calls the method s2(). Since s2() throws an exception, execution of the sl() method is transferred to the catch block. Here, it appends "c" to the value of s.

Control is then transferred back to the s1() method, which then returns to the main method. Finally, the value of s is printed to the console, which is "-c" since the catch block was executed.

Therefore, the answer is: B. -c

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 provided Java snippet contains several syntax errors: mismatched braces, missing parentheses, and inconsistent variable names (X vs x). These prevent successful compilation, making Compilation fails the correct answer; the code never runs, so runtime or output options are invalid.

Multiple choice technology programming languages
  1. abc

  2. abcde

  3. Compilation fails due only to an error on line 7.

  4. Compilation fails due only to an error on line 8.

  5. Compilation fails due only to an error on line 10.

  6. Compilation fails due only to an error on line 11.

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

The code has multiple errors. Line 7 has 'xl' (lowercase L) instead of 'x1', which would cause a compilation error. However, the more critical error for this question is on line 11: 'case x4' attempts to use a variable (x4) in a switch case statement. In Java, switch case expressions must be constant expressions (compile-time constants). While x4 is declared final, it's of type Integer (wrapper class), not int, so it's not a compile-time constant. Cases can only use: constant int values, final int primitives initialized with literals, or enum constants. Integer wrapper objects are never compile-time constants.

Multiple choice technology programming languages
  1. An exception is thrown at runtime.

  2. "String is empty" is printed to output

  3. Compilation fails

  4. "String is not empty" is printed to output.

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

The code uses the bitwise OR operator | instead of the logical OR operator ||. With |, both sides are always evaluated. When str is null, str.length() is still called, causing a NullPointerException at runtime. The fix is to use || which short-circuits: if str == null is true, str.length() is never evaluated.

Multiple choice technology programming languages
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints "sleep".

  4. The code executes normally, but nothing is print ed.

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

The code compiles and runs successfully. Thread.sleep(3000) is a static method that pauses execution for 3 seconds. The InterruptedException is properly declared in the throws clause, satisfying the compiler. After sleeping, 'sleep' is printed to console. This is standard usage - no compilation errors or runtime exceptions occur.

Multiple choice technology programming languages
  1. . Line 1 will not compile

  2. . Line 2 will not compile

  3. . Line 3 will not compile

  4. . Line 4 will not compile

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

Line 1 fails because # is not a valid character to start an identifier in Java - identifiers must begin with a letter, underscore _, or dollar sign $. Line 4 fails because ~ is never valid in an identifier. Lines 2 and 3 compile: $age (dollar is valid) and _height (underscore is valid) are legal identifiers. The key distinction is the allowed starting characters for Java identifiers.

Multiple choice technology operating systems
  1. "Hello" will be printed 3 times

  2. "Hello" will be printed 4 times

  3. "Hello" will be printed 8 times

  4. Error

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

Each fork() call creates a new process, doubling the number of processes. After 3 fork() calls: 1 → 2 → 4 → 8 processes. All 8 processes execute the printf statement, so 'Hello' prints 8 times. This is a classic process creation demonstration in UNIX systems.

Multiple choice technology
  1. parseFloat()

  2. toFloat()

  3. float()

  4. stringToFloat()

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

parseFloat() is the standard JavaScript/ActionScript function that parses a string and converts it to a floating-point number. It extracts the first valid number from the beginning of the string. The other options (toFloat, float, stringToFloat) are not standard functions in JavaScript or ActionScript.

Multiple choice technology programming languages
  1. 234

  2. 334

  3. 2334

  4. 0123456

  5. 01234456

  6. 12334567

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

The regex \d* matches zero or more digits, finding matches at positions 0, 1, 2, 3, 4, 5, 6. The output format shows position+group, giving: 0 + '' (empty match at start), 1 + '' (between a and b), 2 + '' (between b and 3), 3 + 3, 4 + '' (between 3 and 4), 5 + 4, 6 + '' (between 4 and e). This produces 01234456. Option E is correct.

Multiple choice technology programming languages
  1. 8/9/05 5:54 PM

  2. 1123631685981L

  3. An exception is thrown at runtime.

  4. Compilation fails due to a single error in the code.

  5. Compilation fails due to multiple errors in the code.

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

DateFormat is an abstract class and cannot be instantiated directly. You must use concrete subclasses like SimpleDateFormat. The code attempts to create a new DateFormat() on line 5, which will cause a compilation error. Option E is correct - there are multiple compilation errors because DateFormat is abstract and cannot be instantiated.

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.