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. error method main not correct

  2. error Can't make static reference to void a method.

  3. error array must include parameter

  4. a method must be declared with String

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

The non-static method amethod cannot be directly referenced or called from the static main method without instantiating MyClass first. The error message explicitly points out trying to make a static reference to a non-static method, whereas the other options describe unrelated issues.

Multiple choice technology programming languages
  1. float f=1.3;

  2. char c="a";

  3. int i=10;

  4. boolean b=null;

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

In Java, int i=10; is a valid assignment of an integer literal. float f=1.3; fails compilation because 1.3 is double by default and needs an 'f' suffix. char c="a"; fails because double quotes define a String, and boolean is a primitive type that cannot be assigned null.

Multiple choice technology programming languages
  1. 6

  2. 0

  3. 1

  4. 7

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

The bitwise OR operation 4 | 3 works on the binary representations: 4 is 100 and 3 is 011. OR produces 111 (binary) which is 7 in decimal. Each bit position is 1 if either operand has a 1 in that position.

Multiple choice technology embedded technologies
  1. Compilation fails.

  2. The program hangs at line 22.

  3. Out of Memory! is printed to the system console.

  4. An exception is thrown at runtime but there is no guarantee an alert will be shown to the user.

Reveal answer Fill a bubble to check yourself
D Correct answer
Multiple choice technology programming languages
  1. Execution time error

  2. Syntax error

  3. R4R:0

  4. None

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

In C++, when you initialize an integer with leading zeros like 'int a=000', the compiler interprets it as an octal (base-8) literal. However, 000 in octal equals 0 in decimal. So the program prints 'R4R:' followed by '0', giving the output 'R4R:0'. There's no syntax or execution error - the code is valid and runs correctly.

Multiple choice technology programming languages
  1. Execution time error

  2. syntax error

  3. R4R

  4. None

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

The code has a syntax error because the cout statement lacks a terminating semicolon before return 0;. Additionally, `` is an outdated header style, but the missing semicolon directly triggers a compilation syntax error, preventing successful execution or outputting of the string.

Multiple choice technology programming languages
  1. TRUE

  2. MyClass

  3. 1

  4. Object Reference

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

In Perl, bless associates a reference with a class, making it an object. The ref() function returns the class name of a blessed reference. Here, an empty hashref {} is blessed into 'MyClass', so ref($val) returns 'MyClass'. TRUE would be from a boolean context, 1 is numeric truth, and 'Object Reference' is not what ref() returns for a blessed object.

Multiple choice technology programming languages
  1. blah

  2. Empty String

  3. Can't locate object method "new" via package "B"

  4. None of the above

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

Package B uses base 'A' to inherit from A, so B->new() calls A's constructor method which blesses an empty hashref. The returned object is a B instance that can call B's foo method, which returns 'blah'. The code prints 'blah' followed by a newline. Options B and C are incorrect because Perl's inheritance works properly and the foo method exists in package B.

Multiple choice technology programming languages
  1. Compilation error

  2. Runtime error

  3. No errors

  4. Compilation error at statement 2

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

This code performs a valid type conversion: an int is cast to float, then the float is assigned to a double. Both conversions are legal - the cast is explicit (int to float), and the float to double conversion is implicit widening. No compilation or runtime errors occur.

Multiple choice technology programming languages
  1. Compilation error

  2. Runtime Error

  3. Runtime Exception

  4. Output of b is 1

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

The variable 'b' is an instance variable (non-static), but main() is a static method. Static methods cannot directly access instance members without creating an object instance first. This causes a compilation error: 'non-static variable b cannot be referenced from a static context.'

Multiple choice technology programming languages
  1. Compiler error

  2. Runtime Exception

  3. True

  4. False

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

When you use 'new Integer(2)', you create distinct Integer objects on the heap. The '' operator compares object references, not values. Since 'a' and 'b' point to different objects, 'ab' returns false. To compare Integer values, use a.equals(b).

Multiple choice technology programming languages
  1. undef

  2. 0

  3. 1

  4. 2

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

Setting $#a = 0 truncates the array to only its first element (index 0), removing all other elements. The array @a now contains only one element (0). When an array is assigned to a scalar in Perl, it returns the number of elements in the array, so \$size = 1.