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

  2. parentchild 2020

  3. child child2020

  4. parentparent 2020

  5. childchild1010

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

par is the object of parent class so it will call meth() method of parent class, par2 will call the mothod of Test1 class due to overriding but the variable will call only of Parent class because overriding is for methods not for variable

Multiple choice
  1. 0 1 2

  2. 1 2 3

  3. 0 1 2 3

  4. Compilation error

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

The code will not compile because the variable counter is an interface variable that is by default final static. The compiler will complain at line 10 when the code attempts to increment counter. So it provides compilation error.

Multiple choice
  1. 57 22

  2. 45 38

  3. 45 57

  4. An exception occurs at runtime

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

You can define an Inner class as abstract, which means you can instantiate only concrete subclasses of the abstract Inner class. The object refered by the variable is an instance of an anonymous subclass of AbstractTest, and the anonymous class overrides the getNum() method to return 22. The variable referenced by f is an instance of an anonymous subclass of Bar, and the anonymous Bar subclass also overrides thegetNum() method (to return 57). Remember that to instantiate a Bar instance, we need an instance of the enclosing AbstractTest class to tie to the new Bar inner class instance. AbstractTest can't be instantiated because it's abstract, so we created an anonymous subclass (non-abstract) and then used the instance of that anonymous subclass to tie to the new Bar subclass instance.

Multiple choice
  1. Because of the Throw portion of exception.

  2. Because of the Catch portion of exception.

  3. Because of the main() portion.

  4. Because of the class portion.

  5. None of the above

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

Though exception is opened and it is generating the exception also but since catch is missing, so the error is not acknowledged and displayed.

Multiple choice
  1. 9.0

  2. bad number

  3. compilation fails on line 13

  4. compilation fails on line 14

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

The xxxValue() methods convert any numeric wrapper object's value to any primitive type. When narrowing is necessary, significant bits are dropped and the results are difficult to calculate.

Multiple choice
  1. This program will compile successfully.

  2. This program fails to compile due to an error at line 4.

  3. This program fails to compile due to an error at line 6.

  4. This program fails to compile due to an error at line 13.

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

Any method (in this case, the main() method) that throws a checked exception (in this case, out.close() ) must be called within a try clause, or the method must declare that it throws the exception. Either main() must declare that it throws an exception, or the call to out.close() in the finally block must fall inside a (in this case nested) try-catch block.

Multiple choice
  1. Ex0 caught

  2. exception caught

  3. Compilation fails because of an error it line 2

  4. Compilation fails because of an error in line 9

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

An exception Exc1 is thrown and is caught by the catch statement in line 11. 

Multiple choice
  1. 1

  2. 2

  3. 3

  4. Compilation Fails

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

Initially this looks like a question about the logical and logical shortcut operators "|" and "||" but on closer inspection it should be noticed that the name of the boolean method in this code is "catch". "catch" is a reserved keyword in the Java language and cannot be used as a method name. Hence Compilation will fail.

Multiple choice
  1. The program will fail to compile.

  2. The program will compile without any errors and will print 'Hello' and 'World' everytime the program is run.

  3. The program will compile without errors and will print 'Hello' and 'World' but the order is unpredictable.

  4. The program will compile without any errors and will terminate without any output when run.

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

The program will compile without errors and will simply terminate without any output. Two threads are created but they will never be started. The start() method must be called on the thread objects to make the threads execute the run() method asynchronously.

Multiple choice
  1. AB

  2. BC

  3. ABC

  4. BCD

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

(1) A RuntimeException is thrown, this is a subclass of exception. (2) The exception causes the try to complete abruptly (line 5) therefore line 6 is never executed. (3) The exception is caught (line 7) and "B" is output (line 9) (4) The finally block (line 10) is always executed and "C" is output (line 12). (5) The exception was caught, so the program continues with line 15 and outputs "D".

Multiple choice
  1. ABCD.

  2. Compilation fails.

  3. C is printed before exiting with an error message.

  4. BC is printed before exiting with an error message.

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

Error is thrown but not recognised in line(18) because the only catch attempts to catch an Exception and Exception is not a superclass of Error. Therefore, only the code in the finally statement can be run before exiting with a runtime error (Exception in thread main java.lang.Error).

Multiple choice
  1. catch (ArrayIndexOutOfBoundsException aie) {
     aie.printStackTrace();
     System.out.println("array size is less than what you are trying to access")
    }
    
  2. catch (ArrayIndexOutOfBoundsException aie) {
     System.out.println("array size is less than what you are trying to access")
    }
    
  3. catch (aie) {
     aie.printStackTrace();
     System.out.println("array size is less than what you are trying to access")
     }
    
  4. throw (ArrayIndexOutOfBoundsException aie) {
     aie.printStackTrace();
     System.out.println(array size is less than what you are trying to access ')
     }
    
  5. throw (aie) {
     aie.printStackTrace();
     System.out.println(array size is less than what you are trying to access)
    }
    
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Catch routines are defined in this form. 

Multiple choice
  1. This code will not compile due to line 5.

  2. This code will not compile due to line 6.

  3. 1..2..

  4. 1..2..3..

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

Line 6 calls the run() method, so the run() method executes as a normal method should and it prints 1..2.. 1 is incorrect because line 5 is the proper way to create an object. 2 is incorrect because it is legal to call the run() method, even though this will not start a true thread of execution. The code after line 6 will not execute until the run() method is complete. 4 is incorrect because the for loop only does two iterations.

Multiple choice
  1. The code fails to compile in the main() method

  2. The code fails to compile in the run() method

  3. Only the text "In run" will be displayed

  4. The text "In run" followed by "Leaving run" will be displayed

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

The Thread.yield() method suggests to the thread scheduler that the current thread is willing to yield its current use of processor, but the scheduler is free to ignore this suggestion. In this simple single-threaded program, yield() has no visible effect, and both statements execute normally, printing 'In run' followed by 'Leaving run'.