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

Multiple choice technology programming languages
  1. x = 42

  2. x = 43

  3. x = 44

  4. Compilation fails

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

The variable x is declared inside the try block, meaning its scope is limited to that block. It is inaccessible in the catch and finally blocks, causing a compilation error when referenced there. Additionally, the typo X++ (uppercase) and printIn (capital I) would also prevent compilation.

Multiple choice technology programming languages
  1. 1 1

  2. 2 1

  3. 3 1

  4. 4 1

  5. 2 3

  6. 4 3

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

For doX(s,s) with short arguments, boxing to Short (which inherits from Number) is preferred over varargs, resolving to doX(Number, Number) (returning 4). For doX(7,7) with int arguments, boxing to Integer is more specific than Number, resolving to doX(Integer, Integer) (returning 3). Thus, '4 3' is printed.

Multiple choice technology programming languages
  1. hi

  2. hi hi

  3. hi hi hi

  4. Compilation fails

  5. hi, followed by an exception

  6. hi hi, followed by an exception

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

m3.go() prints 'hi'. Then m4=m3.m1 is null since m1 was never initialized. Calling m4.go() throws a NullPointerException. The output is 'hi' followed by the exception.

Multiple choice technology programming languages
  1. true true

  2. true false

  3. false true

  4. false false

  5. Compilation fails.

  6. An exception is thrown at runtime.

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

f1 and f3 reference the same object (z is assigned x, and x is f1). So f1 == f3 is true. The 'final' keyword on f1 and z doesn't prevent modifying the object's fields - it only prevents reassigning the reference. z.x = 6 modifies the same object that f1 references, so f1.x == f3.x (both 6) is true.

Multiple choice technology programming languages
  1. 343 340 340

  2. 343 340 342

  3. 343 341 342

  4. 343 341 340

  5. 343 341 343

  6. Compilation fails.

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

First, static tooth (343L) is printed. Then the local final tooth (340L) is declared. doIt() receives 340, ++tooth makes it 341 (printed), then ++tooth makes it 342 (returned). Back in main, the local tooth is still 341 (not affected by doIt's parameter modifications). Output: 343 341 340.

Multiple choice technology programming languages
  1. Line 4

  2. Line 5

  3. Line 6

  4. Line 7

  5. Line 8

  6. Line 9

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

Java 5 introduced autoboxing and unboxing. In Java 1.4, assigning a primitive long to a Long object (Lines 7 and 8) or assigning a Long object to a primitive long (Line 4) without explicit conversion would fail to compile. These lines compile in Java 5 due to automatic boxing and unboxing.