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. The program will run successfully with no errors or warnings.
    1. The program will halt with a runtime exception.
    1. The program will halt with a compiler error.
    1. The program will run successfully with no errors but a warning will be generated.
Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The array has indices 0-9, but the loop condition x <= 10 includes x=10. Attempting MyInt[10] throws ArrayIndexOutOfBoundsException at runtime. The loop should use x < 10.

Multiple choice technology programming languages
    1. Its: 1
    1. Its: 0
    1. Its: true
    1. Its: 0.0
    1. A compiler error
Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

In Java, local variables must be initialized before use. The variable 'dSyntaxs' is declared but never assigned a value, so attempting to print it causes a compiler error. Java does not automatically initialize local variables (unlike instance fields which get default values). The code will not compile.

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

  2. Error during compilation at line 1

  3. E. Error during compilation at line 2

  4. Error during compilation at line 3

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

Line 2 is invalid because 'z' has not been declared. In Java, you cannot chain assignments like 'int x = z = 1' if 'z' isn't already defined. This causes a compilation error at line 2, and subsequently line 3 fails because 'x' and 'z' are undefined.

Multiple choice technology programming languages
  1. Prints 3

  2. Error during compilation at line 1

  3. Prints 11

  4. Prints 0

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

017 is an octal literal in Java, equal to decimal 15. The (byte) cast doesn't change the value since 15 fits in a byte. Right-shifting 15 (binary 1111) by 2 positions gives 3 (binary 11). Integer.toBinaryString(3) outputs '11'.

Multiple choice technology programming languages
  1. Prints: In Question05Sub

  2. Prints: In Question05

  3. Prints:In Question05In Question05Sub

  4. The code does not compile.

Reveal answer Fill a bubble to check yourself
D Correct answer
Multiple choice technology programming languages
  1. Compilation error.

  2. Prints: 1 3 4 true false true

  3. Prints: 1 2 4 false false true

  4. Prints: 3 4 true true true

  5. None of the above.

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

obj[0]=new Object(), obj[1]=obj[-1] causes ArrayIndexOutOfBoundsException at i=1. However, re-examining: when i=1, i%2==0 is false, so obj[1]=obj[0]. Wait - obj[i-1] when i=1 is obj[0], which exists. So array fills: obj[0]=new Object(), obj[1]=obj[0](same reference), obj[2]=obj[1](same reference). All three entries point to one object. First if: obj[0]obj[1] is true, assignment obj[1]=obj[2] is redundant but not null, prints '1'. Second if: obj[1]obj[2] is true, obj[2]=obj[0] redundant, but && requires both sides - first part true so evaluation continues, prints '2'. Third if: obj[1]obj[0] is true (short-circuit ||), skips assignment, prints '3'. Fourth if: | is non-short-circuit, so assignment executes but obj[0]obj[2] always true, prints '4'. Final comparison: all three are same reference, so 'false false true'. Wait, re-tracing second if: after first if, obj[1]=obj[2](same obj). obj[1]obj[2] is true. && evaluates left to right, both conditions true. But re-reading the && logic more carefully - when obj[1]obj[2] is true, it proceeds to check (obj[2]=obj[0])!=null. That's true. So '2' prints. Option C shows '1 2 4' - let me verify again. Actually looking at the answer C: '1 2 4 false false true'. The obj comparisons at end: obj[0]==obj[1] after all the shuffle... hmm.

Multiple choice technology programming languages
    1. Class A Constructor followed by Class B Constructor
    1. Class B Constructor followed by Class A Constructor
    1. Compile time error
    1. Run time error
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Java, when a subclass object is created, the superclass constructor is called first (implicitly or explicitly). Therefore, A's constructor runs first, followed by B's constructor.

Multiple choice technology programming languages
    1. Compilation error at line 2
    1. Runtime error at line 7.
    1. Compilation error at Line 7
    1. Compiles and prints 0 0 4
    1. Compiles and prints 0 4 0
Reveal answer Fill a bubble to check yourself
A Correct answer
Multiple choice technology programming languages
    1. a sequence of 5 0's will be printed
    1. Error: ar is used before it is initialized
    1. Error Mine must be declared abstract
    1. IndexOutOfBoundes Error
Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Class Mine extends abstract class MineBase but doesn't implement the abstract method amethod(). Therefore Mine must also be declared abstract. Concrete subclasses must implement all inherited abstract methods. The array initialization code is correct (Java arrays default to zero values), but the class declaration is the issue.

Multiple choice technology programming languages
  1. a. Bic

  2. b. ic

  3. c. icy

  4. d. error: no method matching substring(int,char)

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

To solve this question, the user needs to understand the concept of substring and character indices.

The given code creates a string object s with value "Bicycle". The variables iBegin and iEnd have been assigned the values 1 and 3, respectively. The substring method is then called on the string object s with two arguments: iBegin and iEnd. The substring method extracts a portion of the string starting at the index specified by iBegin and ending at the index specified by iEnd-1.

Option A is incorrect because the substring method with arguments (1,3) extracts the portion of the string starting at index 1 and ending at index 2. Thus, the output is "Bi".

Option B is correct because the substring method with arguments (1,3) extracts the portion of the string starting at index 1 and ending at index 2. Thus, the output is "ic".

Option C is incorrect because the substring method with arguments (1,3) extracts the portion of the string starting at index 1 and ending at index 2. Thus, the output is "ic", not "icy".

Option D is incorrect because the syntax of the substring method is correct, and there is a matching method signature that takes an int and a char.

Therefore, the answer is:

The Answer is: B. ic

Multiple choice technology programming languages
  1. A 12

  2. B 012

  3. C 10

  4. D 10.0

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

To solve this question, the user needs to know the basics of Java programming language. The code creates an object of the Oct class and then calls the amethod() method, which initializes an integer variable oi with 012 and prints its value to the console.

In Java, leading zero in an integer literal denotes an octal (base-8) number. Therefore, the value 012 is an octal number that represents the decimal value 10.

So, the correct answer is:

The Answer is: C. 10

Multiple choice technology programming languages
  1. A System.out.println(1+1);

  2. B int i=2+'2';

  3. C String s="on"+'one';

  4. D byte b=255;

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

Statement A is valid (integer addition). Statement B is valid because a char ('2') can be promoted to an int and added to 2. Statement C is invalid because 'one' is not a valid char literal (too many characters). Statement D is invalid because 255 exceeds the byte range (-128 to 127).

Multiple choice technology programming languages
  1. a. Compile time error, main is not correctly defined

  2. b. Run time error, main is not correctly defined

  3. c. Compilation and output of java

  4. d. Compilation and output of hello

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

The main method signature is correctly defined (static void, String array parameter). When running 'java myclass hello', 'hello' becomes args[0]. The program prints parm[0] which is 'hello'. The parameter name 'parm' is unusual but legal - Java doesn't enforce specific parameter names for main.