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 technology programming languages
  1. O

  2. 11

  3. 12

  4. -3

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

To solve this question, the user needs to understand the basic control flow of the while loop and the concept of variable assignment.

The code initializes the variable k to 0 and the variable n to 12. The while loop continues running as long as the value of k is less than the value of n. In each iteration of the loop, the value of k is incremented by 1.

Since the loop runs 12 times, the value of k will be incremented 12 times. Therefore, at the end of the loop, the value of k will be equal to 12.

Now, let's go through each option and explain why it is right or wrong:

A. O: This option is incorrect because the value of k is incremented 12 times, resulting in a final value of 12, not 0.

B. 11: This option is incorrect because the value of k is incremented 12 times, resulting in a final value of 12, not 11.

C. 12: This option is correct. The value of k is incremented 12 times, resulting in a final value of 12.

D. -3: This option is incorrect because the loop increments the value of k by 1 each time, and the starting value of k is 0. Therefore, the value of k can never be negative.

The Answer is: C

Multiple choice technology programming languages
  1. DoubleField

  2. TextField

  3. IntField

  4. double

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

The setDouble() method name indicates it accepts a double value. Since huey is an object with methods (not a primitive), it must be of a wrapper type like DoubleField, not the primitive double type. Option A DoubleField is the correct object type that would have a setDouble() method.

Multiple choice technology web technology
  1. compile time error at line1

  2. compile time error at line2

  3. compile time error at line3

  4. Runtime exception

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

In Java, arrays have a length property (not a method). Line 1 attempts to call a1.length() which is a compile-time error because arrays don't have a length() method - they use the length property. Strings have length() method, but arrays use length directly. Option A correctly identifies this compile-time error.

Multiple choice technology programming languages
  1. prints object created

  2. Compile time error

  3. Runtime Excepion

  4. None of the above

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

The code is valid Java - a static nested class inside a static interface inside a class can be instantiated using the full qualified name C1.I.C2. Static members don't require an instance of the outer class.

Multiple choice technology programming languages
  1. prints 0

  2. Compile time error

  3. Runtime exception

  4. None of the above

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

The code compiles and runs successfully. Static int i1 is automatically initialized to 0 by Java. The class C2 is static and accessible via C1.C2 without needing an instance.

Multiple choice technology programming languages
  1. 10

  2. 12

  3. compilation error

  4. none of these

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

In the setnum method, the parameter 'int num' shadows the instance variable 'int num'. When we write 'num = num' inside the method, we're assigning the parameter value to itself, not updating the instance variable. Therefore, the instance variable remains 12, which is what getnum() returns. The local scope takes precedence over the instance variable.

Multiple choice technology programming languages
  1. class cons{ cons() { } public void cons(); public static void main (String[] aa){ cons b=new cons(); } }

  2. public class cons { ............... cons() { } public cons(int x,int y) { System.out.print(x +" "+ y); } public static void main (String[] aa){ cons b=new cons(); cons obj=new cons(4,2); }

  3. public class cons { public cons(int x) { System.out.print(x); } public static void main (String[] aa){ cons b=new cons(); } }

  4. class cons{ cons() { } public float foo () { double f = 32; return f; } public static void main (String[] aa){ cons b=new cons(); } }

Reveal answer Fill a bubble to check yourself
B Correct answer
Multiple choice technology programming languages
  1. 10

  2. 12

  3. compilation error

  4. none of these

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

In the setnum method, num = num assigns the local parameter num to itself due to variable shadowing, leaving the instance variable this.num unchanged. Therefore, getnum() returns the initial value of the instance variable, which is 12.

Multiple choice technology programming languages
  1. class cons{ cons() { } public void cons(); public static void main (String[] aa){ cons b=new cons(); } }

  2. public class cons { cons() { } public cons(int x,int y) { System.out.print(x +" "+ y); } public static void main (String[] aa){ cons b=new cons(); cons obj=new cons(4,2); } }

  3. public class cons { public cons(int x) { System.out.print(x); } public static void main (String[] aa){ cons b=new cons(); } }

  4. class cons{ cons() { } public float foo () { double f = 32; return f; } public static void main (String[] aa){ cons b=new cons(); } }

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

The second option compiles and runs successfully because it defines both a default constructor and a parameterized constructor, matching the instantiations in main. The first option has a method signature without a body, the third lacks a default constructor, and the fourth attempts to return a double as a float without casting.

Multiple choice technology programming languages
  1. Compilation error on line 1

  2. Compilation error on line 2

  3. Compilation error on line 3

  4. Line 3 compiles fine

  5. Prints 10 random numbers between 0 and 127

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

The for loop condition uses '<>' which is not a valid Java operator - it should be '<' or '>'. This causes a compilation error on line 1. Line 3 compiles fine because Math.random()*b produces a double which can be cast to short without error, even though the method returns int. The code structure is valid apart from the invalid loop operator.

Multiple choice technology programming languages
  1. Wrapper Type Call

  2. Primitive Type Call

  3. Compiler Error

  4. Compiles fine, throws runtime exception

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

When a primitive byte is passed to overloaded methods, Java prefers the primitive method(int) over autoboxing to method(Integer). The compiler chooses the most specific match without requiring autoboxing.

Multiple choice technology programming languages
  1. The program will not compile because the creation of bool4 object will cause compilation error.

  2. The program will produce the output 'true false false'.

  3. The program will produce the output 'true true true'.

  4. The program will output 'true false true'.

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

bool1.equals(bool4) returns true because both contain value 'true'. bool2 == bool3 returns false because they are different object references. bool1 == bool4 returns false because 'new' creates separate objects.

Multiple choice technology programming languages
  1. The program won't compile.

  2. The program will throw a run-time exception.

  3. The program will output '31 100'

  4. The program will output '31 99'

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

The program will not compile because a = 30 assigns an int literal to an Integer reference without autoboxing, and the post-increment a++ on an Integer reference is followed by assignment a = s which mixes operations ambiguously. Java requires explicit boxing or proper reference handling.

Multiple choice technology programming languages
  1. The program will raise a run-time exception telling that it is not possible to skip bytes in the middle of a reading operation.

  2. The program will output 'd'.

  3. The program will output 'e'.

  4. The program will output 'g'.

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

read() is called twice (consumes 'a' and 'b'), skip(4) skips 'c','d','e','f'. The next read() returns 'g' (position 6, zero-indexed). The skip() method advances the stream position by 4 bytes.