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. Hash is: 111111, 44444444, 999999999

  2. Blank output screen

  3. An exception is thrown at runtime

  4. Compilation Fails

  5. None of these

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

This is the correct choice. The compilation fails as SampleClassA and SampleClassB cannot override SampleClass’s getHash() method because the return type of SampleClass’s getHash() method is int, while the return type of SampleClassA and SampleClassB is long. Note: If all three classes had the same return type, the output would be: Hash is : 111111, 44444444, 999999999 So, this is the correct choice.

Multiple choice
  1. 1 null

  2. Null null

  3. 2 an ArrayIndexOutofbound Exception is thrown

  4. ArrayIndexOutofbound Exception is thrown

  5. Compilation fails

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

This is the correct answer. The first println statement, System.out.println(array [2][1]), works fine. It selects the element/array with index 2, {0, 2,4}, and from this array it selects the element with index 1 which is 2. So, 2 gets printed. The second println statement, System.out.println(array) [2][4]), fails. It selects the array/element with index 2,{0, 2, 4}, and from this array, it tries to select the element with index 4. This causes an exception. So, an exception in thread main java.lang.ArrayIndexOutOfBoundsException occurs.

Multiple choice
  1. Hello

  2. 0

  3. Run time error

  4. Compilation error

  5. Blank output screen

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

This is the correct choice. Class ScopeTest extends class A. When we create an object of class ScopeTest, it automatically calls the non-argument constructor of class A, but there is no such constructor in class A. So, the compiler will throw an error. If we add a non-argument constructor (as shown below) in class A, then the code will compile.A(){} So, this answer is true.

Multiple choice
  1. Zero times

  2. Once

  3. Twice

  4. Thrice

  5. Compilation fails

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

This is the correct choice. For statement, (String ss: table), is executed one time for each of the three elements in table. The while loop will print 1 once for each element. The output comes out to be : aa, 0aa, 1aa, 2bb, 0bb, 1bb, 2cc, 0cc, 1cc, 2 So, 1 will be printed 3 times, hence this answer is correct.

Multiple choice
  1. o

  2. c

  3. Empty string

  4. Compile time error

  5. Run time error

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

This is the correct answer. Substring method takes two parameters (BeginIndex, EndIndex).Substring(int Begin, int End). It returns the string from the beginning to end – 1. But if the BeginIndex is equal to the EndIndex, then an empty String with length 0 will be returned. So, here substring(4, 4) will return an empty string of length 0.  

Multiple choice
  1. a

  2. v

  3. Compiler Error : cannot pass a function as parameter

  4. Compiler Error : parameters not sufficient

  5. Run time error

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

This is the correct answer. s.length() will return 15 because there are 15 characters in the string. So, the code looks like this: s.charAt(15); the index count starts at 0. In this way, the last character is 'a' at index number 14. So, if we try to access a character in a string which is out of bound, then a runtime exception “StringIndexOutOfBound” will be thrown. So, we can pass only till s.charAt(s.length()-1).

Multiple choice
  1. -2147483648 and 1

  2. 0x80000000 and 0x00000001

  3. -2147483648 and -1

  4. 1 and -2147483648

  5. None of these

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

Option (1) is correct. The >>> operator moves all bits to the right, zero filling the left bits. The bit transformation looks like this: Before: 1000 0000 0000 0000 0000 0000 0000 0000 After: 0000 0000 0000 0000 0000 0000 0000 0001 Converting this into decimal, the result will be 2147483648 and 1 So, this is the correct choice.

Multiple choice
  1. ome

    • 1
  2. com

  3. Runtime error

  4. Compile time error

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

This is the correct answer. Substring method takes two parameters (beginIndex,EndIndex). Substring( int Begin , int End). It returns the string from begin to end -1. But if the begin index is greater than the end index then a runtime error will occur. So here substring(4,3) will give a runtime error.

Multiple choice
  1. True

  2. False

    • 1
  3. Compile time error

  4. Runtime error

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

This is the correct answer. The compiler will throw an error that method match() was not declared. Because String class does not contain any method named match(). The correct method is matches(). So the above statement should be s.matches(s1). So this is the correct answer. The program will not run. So run time error cannot occur because a compiler error is there. So this is wrong.

Multiple choice
  1. Welcome ava

  2. Welcome va

  3. Welcomeava

  4. Compiler error : delete cannot be used with StringBuffer

  5. Runtime error

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

This is the correct answer. delete(int start , int end) method deletes the characters from the start index until  the end -1 index. So, the welcome to java will delete the characters from 8 to 11 characters. Therefore, the resulting string remains “ Welcome ava”. The index starts from 0.

Multiple choice
  1. o

  2. c

  3. Empty string

  4. Compile time error

  5. Runtime error

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

This is the correct answer. Substring method takes two parameters (beginIndex,EndIndex).Substring( int Begin , int End). It returns the string from begin to end – 1. But if the begin index is equal to the end index then an empty String with length 0 will be returned. So here substring(4,4) will return an empty string of length 0. So this is the correct answer.

Multiple choice
  1. s.length() = 14s.charAt(9) = T

  2. s.length() = 15s.charAt(9) = o

  3. s.length() = 15s.charAt(9) = T

  4. s.length() = 14s.charAt(9) = o

  5. Compiler error

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

This is the correct answer. Length() function returns the number of characters in the string. The number of characters in the given string is 15. So length() will return 15.charAt() function return the character at the given index in the parameter. Remember that the index count starts at 0. So charAt(0) is W. Counting in this way we reach charAt(9) is o. So this is the correct answer.