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. no code is necessary

  2. throws Exception

  3. catch ( Exception e )

  4. throws RuntimeException

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

Option 2 is correct. This works because it DOES throw an exception if an error occurs. Option 1 is wrong. If you compile the code as given the compiler will complain: unreported exception must be caught or declared to be thrown The class extendsException so we are forced to test for exceptions. Option 3 is wrong. The catch statement belongs in a method body not a method specification. Option 4 is wrong. TestException is a subclass of Exception therefore the test method, in this example, must throw TestException or some other class further up theException tree. Throwing RuntimeException is just not on as this belongs in thejava.lang.RuntimeException branch (it is not a superclass of TestException). The compiler complains with the same error as in A above.

Multiple choice
  1. BD

  2. BCD

  3. BDE

  4. BCDE

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

A Runtime exception is thrown and caught in the catch statement in line 10. The code after the finally statement is run because the exception has been caught.

Multiple choice
  1. ACCBAD

  2. ABBCAD

  3. CDDACB

  4. Indeterminate output

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

It gives different output while executing the same compiled code at different times. C:>javac Test.java C:>java Test ABBCAD C:>java Test ACADCB C:>java Test ACBCBAD C:>java Test ABBCAD C:>java Test ACBCBAD C:>java Test ACBCBAD C:>java Test ABBCAD

Multiple choice
  1. Compilation error.

  2. Will print in this order: x = 1 y = 1 x = 2 y = 2 x = 3 y = 3 x = 4 y = 4 x = 5 y = 5... but the output will be produced by both threads running simultaneously.

  3. Will print in this order: x = 1 y = 1 x = 2 y = 2 x = 3 y = 3 x = 4 y = 4 x = 5 y = 5... but the output will be produced by first one thread then the other. This is guaranteed by the synchronised code.

  4. Will print in this order x = 1 y = 2 x = 3 y = 4 x = 5 y = 6 x = 7 y = 8...

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

Both threads are operating on the same instance variables. Because the code is synchronized, the first thread will complete before the second thread begins. Modify line 17 in the following way to print the thread name. System.out.println(Thread.currentThread().getName() + x = + x + , y = + y);

Multiple choice
  1. It will print the numbers 0 to 19 sequentially.

  2. It will print the numbers 1 to 20 sequentially.

  3. It will print the numbers 1 to 20, but the order cannot be determined.

  4. The code will not compile.

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

You have two different threads that share one reference to a common object. The updating and output takes place inside the synchronized code. One thread will run to complete printing the numbers 1-10. The second thread will then run to complete printing the numbers 11-20.

Multiple choice
  1. 0

  2. Compile Time Error

  3. 20

  4. 020

  5. 200

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

since i is protected and it will be visible at all its sub classes

Multiple choice
  1. Displays a rectangle of 200X200 pixels starting with top left corner at 40X40 pixels

  2. Displays a rectangle of 40X400 pixels starting with top left corner at 200X200 pixels

  3. Displays a circle of 200X200 pixels starting with top left corner at 40X40 pixels

  4. Displays a circle of 40X40 pixels starting with top left corner at 200X200 pixels

  5. None of the above

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

This statement will draw the rectangle of 200X200 at left corner at 40X40 of the screen.

Multiple choice
  1. Frame is not defined properly.

  2. Statement import java.awt.*; is missing.

  3. Statement import java.net.*; is missing.

  4. Statement import java.io.*; is missing.

  5. Set size is not defined properly.

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

This statement is must, because awt application is used to create the frame. This application is missing.

Multiple choice
  1. 34

  2. 35

  3. 24

  4. Run time error

  5. Compilation error

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

The two elements 3 and 4 (starting from position with index 2) are copied into position index 1 and 2 in the same array. After the array copy command, the array looks like: {1, 3, 4, 4, 5}.Then, element with index 1 is printed: 3. Then, element with index 4 is printed: 5.

Multiple choice
  1. They Match They Really Match

  2. They really Match

  3. They Match

  4. Blank Output Screen

  5. Compilation fails

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

Strings cannot be compared with the usual <, <=, >, or >= operators, and the == and != operators don't compare the characters in the strings.  

Multiple choice
  1. They matchThey really match

  2. They really match

  3. They match

  4. Nothing will be printed

  5. Compilation fails

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

The strings are not the same objects. So, the == comparison fails. As the values of the strings are the same, equals is true. The equals method compares values for equality. == compares references, not values. The use of == with object references is generally limited to the following: Comparing to see if a reference is null. 

Multiple choice
  1. Blank output screen

  2. StringIndexOutofBound exception

  3. ArrayIndexOutofBound exception

  4. ‘\0’ will be printed

  5. Compilation fails

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

There are only 11 characters in the string hello world. The code theString.charAt(11) retrieves the 12th character, which does not exist. A StringIndexOutOfBoundsException is thrown. Exception in thread main is java.lang. StringIndexOutOfBoundsException. So, this answer is correct.

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

The above program produces output: aa, 0aa, 1aa, 2bb, 0bb, 1bb, 2cc, 0cc, 1cc, 2. So, 2 will be printed thrice. Hence, this answer is false.