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

  2. I am in Static. I am in Static1.

  3. Run time exception

  4. Compiler error

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

Static blocks execute when the class is loaded, even if no objects are created. Since main() is static, merely loading the class to execute main() triggers all static blocks in order. Instance initialization blocks and constructors only run when 'new' is used.

Multiple choice technology programming languages
  1. P in sub class ... 200

  2. Compiler error

  3. P in parent class...100

  4. Run time exception

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

Static methods are resolved at compile‑time based on the reference type. The variable tsv is declared as TestStaticSub, so TestStaticSub.printP() is called, which prints the unchanged static field p (100). The subclass’s method is never invoked, making the stored answer correct.

Multiple choice technology programming languages
  1. p== 500 p== 100

  2. Run time exception

  3. Compiler error

  4. p== 500 p== 500

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

You cannot use 'this' inside a static method because 'this' refers to the current instance, but static methods belong to the class not to any instance. The compiler will catch this error at compile-time. The static variable 'p' should be accessed directly or via the class name, not through 'this'.

Multiple choice technology programming languages
  1. AB

  2. BC

  3. AE

  4. BE

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

Running with -ea enables assertions. If no arguments are passed (length 0) or more than one argument is passed (length 2 or more), the assertion a.length == 1 fails, raising an AssertionError.

Multiple choice technology programming languages
  1. testclone1 intArray[0] = 1400 testclone1one2 intArray[0] = 1400 testclone1 value of number = 1200 testclone2 value of number = 100

  2. testclone1 intArray[0] = 1200 testclone1one2 intArray[0] = 1400 testclone1 value of number = 1200 testclone2 value of number = 100

  3. testclone1 intArray[0] = 1400 testclone1one2 intArray[0] = 1400 testclone1 value of number = 1200 testclone2 value of number = 1200

  4. Compiler Error

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

Object.clone() performs shallow copy. Primitive 'number' is copied (testclone1.number=1200 doesn't affect testclone2.number which stays 100). But 'intArray' is a reference, so both objects share the same array. When testclone2.intArray[0]=1400 executes, it overwrites the earlier testclone1.intArray[0]=1200 assignment. Both objects now have intArray[0]=1400 because they reference the same array.

Multiple choice technology programming languages
  1. Null pointer Exception

  2. Fle Name = test_file.txt Fle Name = test_file.txt

  3. Compiler Error

  4. Fle Name = test_file.txt Fle Name = test_file2.txt

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

The File object maintains its reference regardless of file system state. file.getName() returns 'test_file.txt' initially. After file.delete(), the file is removed but the File object still holds the original name. The renameTo() operation fails (returns false) because the file was already deleted, so getName() still returns 'test_file.txt'. The File object's state doesn't automatically sync with the filesystem.

Multiple choice technology programming languages
  1. Fle Name = test_file.txt File Status = false

  2. Compiler Error

  3. Null Pointer Exception

  4. Fle Name = test_file.txt File Status = true

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

The File constructor in Java does not create a file on the disk or check for its existence; it merely creates an in-memory representation of the path. Thus, getName() returns the file name string "test_file.txt", and exists() returns false.

Multiple choice technology programming languages
  1. True

  2. False

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

Integer division by zero (e.g., 5/0) throws ArithmeticException, unlike floating-point division by zero (e.g., 5.0/0) which produces Infinity. This is because integer arithmetic cannot represent infinity - the operation is undefined for integers and must signal an error.

Multiple choice technology programming languages
  1. Compiler Error

  2. Exception

  3. p = 0

  4. p = 10

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

The method TestConstructor has a void return type, making it a regular method instead of a constructor. Since no valid constructor is defined, Java will provide a default no-arg constructor. However, the code attempts to call TestConstructor(10) which doesn't exist as a constructor.

Multiple choice technology web technology
  1. p = 10

  2. p = 0

  3. Compiler Error

  4. Exception

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

In Java, a constructor call (this()) must be the first statement in a constructor. Here, the parameterized constructor attempts to assign this.p=p and print before calling this(), which violates this rule. The compiler enforces that constructor chaining happens first.

Multiple choice technology programming languages
  1. I am in Constructor p = 10

  2. I am in Constructor p = 0

  3. Compiler Error

  4. Exception

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

The parameterized constructor correctly calls this() as its first statement, executing the no-arg constructor first. It prints 'I am in Constructor', then assigns p and prints 'p = 10'. The output is the concatenation of both print statements.

Multiple choice technology programming languages
  1. Message Hello

  2. I am in Constructor

  3. Compiler Error

  4. Exception

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

The class has two overloaded main methods - one with String[] args and one with String args. When the JVM launches, it calls the standard main(String[] args) which invokes the no-arg constructor, printing 'I am in Constructor'. The second main method is never called.

Multiple choice technology programming languages
  1. Compiler Error

  2. Exception

  3. I am in Constructor

  4. Message Hello

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

The main method is not declared static, which is required by the JVM. When you try to run this class, the JVM cannot find a valid entry point and will throw an exception at runtime stating that the main method must be static.

Multiple choice technology web technology
  1. ab

  2. abcd

  3. ab cd

  4. a b c D

  5. Compilation fails

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

The variable s is declared inside the try block but used in the while condition. However, s is not properly initialized or assigned before use. More critically, br.flush() is called on BufferedReader which doesn't have a flush() method - only the underlying Writer does. This causes compilation failure.

Multiple choice technology web technology
  1. List<List<Integer>> table = new List<List<Integer>>();

  2. List<List<Integer>> table = new ArrayList<List<Integer>>();

  3. List<List<Integer>> table = new ArrayList<ArrayList<Integer>>();

  4. List<List, Integer> table = new List<List, Integer>();

  5. List<List, Integer> table = new ArrayList<List, Integer>();

  6. List<List, Integer> table = new ArrayList<ArrayList, Integer>();

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

The code creates a 2D table using nested loops, so table must be a List of List. Option B correctly declares List> table = new ArrayList>() - ArrayList implements List, and the generic type matches. Option A fails because List is an interface and cannot be instantiated. Option C fails because ArrayList> cannot be assigned to List> - the inner generic type must match exactly. Options D-F use invalid syntax with commas instead of proper generic notation.