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

  2. False

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

Java supports implicit type widening or promotion from lower precision to higher precision types. For example, byte (8 bits) can be assigned to int (32 bits), or int can be assigned to long. This is safe because the destination type can accommodate all possible values of the source type without data loss. The reverse (higher to lower precision) requires explicit casting.

Multiple choice
  1. Base Class

  2. Derived Class

  3. No output. A Compilation Error

  4. No output. A Runtime Error

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

Runtime binding of a virtual function based on the object the pointer is pointing to. This is called Runtime Type Identification (RTTI).

Multiple choice
  1. Base Class

  2. Derived Class

  3. No output. A Compilation Error

  4. No output. A Runtime Error

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

Compile time binding of a non-virtual function is based on the data type of the pointer.

Multiple choice
  1. 0

  2. 1

  3. 4

  4. 8

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

An invisible virtual pointer is automatically inserted in a class when at least one of its methods is declared as virtual. The size of a pointer is 4 bytes.

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

  2. 15

  3. 100

  4. 65

  5. None of the above

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

  Key concepts: this is used to access methods or variables of the current class. super is used to access methods or variables of the base class. Program execution after creating object for child class C , is given as follows ||| |---|---| |class A {   int a,b;   A()   {      a=20;      b=30;   } }|a=20, b=30| |class B {   int a=10,b=5;   B()   {      a=this.a+super.a;      b=this.b+super.b;   } }|a=10+20=30, b=5+30=35  | |class C {   C()   {      System.out.println(super.a+super.b);   } }|prints a+b value a+b=30+35=65| | |Hence 65 is the output of the given program|

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. It is a class in java.lang package.

  2. It is a static object of PrintStream class.

  3. It is a method in the PrintStream class.

  4. It is a reference variable of the System class.

  5. Both (2) and (4).

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

This is the correct choice.