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

  2. 0104505

  3. 0104545

  4. error:non static object cannot be referenced from static context

  5. 01045

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

It is the correct choice as it has to create call through object like ob1.test(), without which it is creating an error.

Multiple choice
  1. point

  2. Point

  3. [0, 0]

  4. [10, 0]

  5. [10, 20]

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

The assignment x = x; inside the construct reassigns the passed parameter. It does not assign the memberx in sample5. The correct way to perform the assignment is this.x = x;. Field y is not assigned, so its value remains 0.

Multiple choice
  1. 0

  2. Error in the importing package

  3. Compile time error

  4. 1

  5. Both 2 and 3

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

Correct choice System class is present in java.lang package. As it is a final class, it calls println() through static printstream object out, so we initially import static java.lang.System.out, which initially declares static object out.

Multiple choice
  1. When executed, this program printsk == j is falsek.equals(j) is false

  2. When executed, this program printsk == j is truek.equals(j) is false

  3. When executed, this program printsk == j is falsek.equals(j) is true

  4. When executed, this program printsk == j is truek.equals(j) is true

  5. When compiled, the program will result in a compiler error in the line marked with the comment INCR.

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

Equals () function return true when they have same memory location assigned to it.

Multiple choice
  1. s1 and s2 equal s1 and s3 equal

  2. s1 and s2 equal s1 and s3 not equal

  3. s1 and s2 not equal s1 and s3 not equal

  4. s1 and s2 not equal s1 and s3 equal

  5. None of the above

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

JVM sets a constant pool in which it stores all the string constants used in the type. If two references are declared with a constant, then both refer to the same constant object. The == operator checks the similarity of the objects itself (and not the values in it). Here, the first comparison is between two distinct objects, so we get s1and s2 not equal. On the other hand, since references of s1 and s3 refer to the same object, we get s1 and s3 equal.

 

Multiple choice
  1. a1 == a2 is falsearr1.equals(arr2) is falseArrays.equals(a1, a2) is true

  2. a1 == a2 is truea1.equals(a2) is falseArrays.equals(arr1, arr2) is true

  3. a1 == a2 is falsearr1.equals(a2) is trueArrays.equals(a1, a2) is true

  4. a1 == a2 is truea1.equals(a2) is trueArrays.equals(a1, a2) is false

  5. a1 == a2 is truea1.equals(a2) is trueArrays.equals(a1, a2) is true

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

The first comparison between two array objects is carried out using the == operator, which compares object similarity, so it returns false here. The equals() method, which compares this array object with the passed arrayobject, does not compare values of the array since it is inherited from the Object class. Thus we get another false. On the other hand, the Arrays class implements various equals() methods to compare two array objects of different types, hence we get true from the last invocation.

Multiple choice
  1. In sample8.sample8a()In sample8.sample8b()

  2. In sample8.sample8a()In childsample8.sample8b()

  3. In childsample8.sample8a()In sample8.sample8b()

  4. In childsample8.sample8a()In childsample8.sample8b()

  5. None of the above

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

Reference variable is of type sample8(super class) and object created is of childsample8() and as it is static, so it first call sample8a() method of super class statically and then it calls sample8b() method of derived class dynamically.

Multiple choice
  1. sample10.new sample10a().text

  2. new sample10.sample10a().text

  3. sample10.sample10a.text

  4. new sample10().sample10a.text

  5. none of the above

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

The correct way to access fields of the static inner class is to use the inner class instance along with the outerclass, so new sample10.sample10a().text will do the job.

Multiple choice
  1. 10

  2. 25

  3. Garbage value

  4. Error in the program

  5. None of these

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

This is the correct option because the scope of static variable is throughout the program, hence the assignment at line 4 changes the value of static variable to 25. So this is the correct answer.

Multiple choice
  1. 10, 20

  2. 20, 10

  3. 20, 20

  4. 10, 10

  5. Error in the program

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

Here we are calling swap() by passing address of the parameters. This is called call by reference. Line 4 : void swap(int*,int*); <= this is the prototype of function and parameters are type of int* (Integer pointer), it stores the address of integer variable. Line 6 : swap(&a,&b); <= Calling swap function by passing address of  a and b using '&' operator. a | 10 |    b | 20 |  Line 9:  Now memory address of a and b are copied to x and y, so x and y too start pointing same memory as a and ba | 10 | <--xb | 20 | <--y Now values at memory location where x and y are pointing are swapped( Line 10, 11 and 12)[*x => value at memory location where x is pointing.]a | 20 | <--xb | 10 | <--y Now, you can see a and b memory location is same but values are changed. So this is the correct answer.

Multiple choice
  1. 20.99000

  2. 20.00000

  3. 20

  4. 20.9

  5. Error in the program

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

There is an error in the program, so it will not show any output in the main function. Definition of func() is not known to compiler during compilation, so compiler assumed the return type and parameter type to int but in definition. When it sees the parameter type is float, it throws conflicting types error. So this is the correct choice.

Multiple choice
  1. 10

  2. 20

  3. 0

  4. Garbage value

  5. Compilation error

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

There is an error in the program, it will not show any output as when we write i=20 in the global scope, it is considered as a declaration and not just an assignment and the compiler assumes it as int i=20. Hence the compiler reports an error that there is a non-static declaration of 'i' after the static declaration of i, which is not allowed. So this option is correct.