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

  2. 45.6567

  3. 0.6567

  4. Run time Exception

  5. None of the above

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

As variable 'i' is of double and 'j' is of float , we cannot assign a data type with lower precedence with data type of higher precedence. Explicit type cast must be done in order to assign a data type with lower precedence with a data type of higher precedence. i.e float j=(float)i; which type casts the double datatype to float data type As the explicit type casting is not done in the given program, hence we get run time exception.

Multiple choice
  1. a=21 b=31 b=22 b=32

  2. a=22 b=32 b=22 b=32

  3. a=22 b=32 b=21 b=31

  4. a=20 b=30 b=20 b=30

  5. None of the above

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

 Static variable share common memory for different objects.All the object of a class having static variable will have same instance of static variable.Static variables are intialized only once. Now according to program a,b are static variables and are intialized with integer values 20,30 respectively. A a1=new A(); creates object a1, invokes constructor and increments both a and b. Now a=21 b=31 until a1 object creation A a2=new A(); creates object a2, invokes again constructor and increments both a and b. Now a=22 b=32 until a2 object creation a1.func();   //prints a=22. b=32 as a,b are static varibles a2.func();   //prints a=22 b=32 as a,b are static varibles

Multiple choice
  1. true true

  2. true false

  3. false true

  4. false false

  5. Error in the program

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

A c=new C(); //parent class which is a interface reference variable refers to object of child class Hence object 'c' created for child class using parent class reference variable. System.out.println(c instanceof B); // B is the parent class of C hence c is the instanceof B also. Hence prints true. System.out.println(c instanceof A); // A is implemented by child class B which is inherited again by child class C. Hence object 'c' can also implement interface A. Hence prints true. Output is: true true

Multiple choice
  1. 1 2 3 4 5 6

  2. 1 2 3 5 8

  3. 1 2 3 5 8 13

  4. 1 2 3 5 8 13 21

  5. Error in the program

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

int a[]=new int[8]; //creates integer array of size 8.First two elements of the array are initialized with 0,1 respectively and the logic is other elements in the array are computed by adding the previous two elements. a[2]=a[1]+a[0]=1+0=1; a[3]=a[2]+a[1]=1+1=2; a[4]=a[3]+a[2]=2+1=3; a[5]=a[4]+a[3]=3+2=5; a[6]=a[5]+a[4]=5+3=8; a[7]=a[6]+a[5]=8+5=13; a[7] is last element which is computed because a.length-1=8-1=7; Hence, the output is 1 2 3 5 8 13

Multiple choice
  1. 12.56

  2. 12.4

  3. 12

  4. Error in the program

  5. None of the above

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

Here class C implements interface A, by analysing the program, the output is pi*r*r; Already r=2 by calling c. Area(2), we are supplying r=2; in interface pi=3.14, but in class C , pi=3.1, as pi=3.1 is local in class C, hence it hides the actual value of pi=3.4, which is drawn from interface A. Hence pi=3.1,  3.1*2*2=12.4 It prints 12.4 as ouput.

Multiple choice
  1. Example Java

  2. This is Program

  3. This is Example Java Program

  4. This is Example Java

  5. None of the above

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

 StringBuilder class an API compatible but no guarentee of synchronization. It creates a string mutable sequences of characters. Now b is the object of String Builder class which creates string as show below ||||||||||||||||||||||| |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---| |Sequence of characters|T|h|i|s| |i|s| | |J|a|v|a| |P|r|o|g|r|a|m| |index|0|1|2|3|4|5|6|7|8|9|10|12|13|14|15|16|17|18|19|20|21|

b.replace(8, 12, "Example Java"); // which replaces given string built from start index 8 to end index 12 with "Example Java" without effecting the remaining indexes of the string.Hence characters of string from index 8 to 12 are replaced with "Example Java". Now the string looks as show below |||||||||||||||||||||||||||||| |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---| |Sequence of characters|T|h|i|s| |i|s| |E|x|a|m|p|l|e| |J|a|v|a| |P|r|o|g|r|a|m| |index|0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|

Hence  "This is Example Java Program" is the output of the program.  

Multiple choice
  1. 012345

  2. Compile time error

  3. Code will not produce output

  4. It will show error in Object o=i; and in for(int i3:i2)

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

This code demonstrates array type covariance and casting. An int array can be assigned to an Object reference, then cast back to int array. The for-each loop prints 012345. No errors occur.

Multiple choice
  1. Compile error

  2. 10

  3. Run time error

  4. Zero

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

The code creates an ArrayList, adds 10, retrieves index 0, and prints it. This compiles and runs successfully, outputting 10. ArrayList stores Integer objects; get() returns an Integer which is auto-unboxed to int. No compilation or runtime errors occur.

Multiple choice
  1. Run time error

  2. Compile time error

  3. 12345

  4. hello

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

The String.valueOf() method converts the integer 12345 to its string representation "12345". The original string "hello" is overwritten when str is reassigned. The output is simply the string "12345" printed to console.

Multiple choice
  1. Run time error

  2. Compile time error

  3. C=3

  4. Garbage value

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

The code performs simple integer addition: a=1, b=2, so c=a+b equals 3. The println statement concatenates "C=" with the value of c (3), producing "C=3" as output. There are no compilation or runtime errors.

Multiple choice
  1. Compile time error

  2. Run time error

  3. 99.000000000000

  4. 99

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

A long value (99L) is explicitly cast to an int using (int) bvalue. Since 99 fits within the range of int (-2^31 to 2^31-1), the cast succeeds without data loss. The output is simply 99, not 99.0 or any decimal representation.