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. true false

  2. true true

  3. false true

  4. false false

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

f1 is declared final but passed to FizzSwitch. The method parameter x receives the reference, z is assigned x (both point to f1). z.x modifies the instance field, not the reference. The method returns z, which is the same object as f1. f1 == f3 is true (same reference). f1.x was modified to 6, so f1.x == f3.x is also true.

Multiple choice technology programming languages
  1. compiletime error at lines

  2. compiltime error at line 4,5

  3. compiletime error at line 3

  4. Runtime Exception

  5. None of the above

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

In Java, arrays must be declared with brackets after the type or variable name, not C-style syntax. Line 3 uses correct syntax int[][] a1 = new int[3][3]. Line 4 attempts C-style declaration int a2[4] which is invalid. Line 5 declares int a2[5] without initialization using C-style which is also invalid.

Multiple choice technology programming languages
  1. compiletime error at lines 1,2,3,4

  2. compiletime error at line 3

  3. compiletime error at line 1

  4. compiletime error at lines 3,4

  5. None of the above

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

To solve this question, the user needs to know about the different access modifiers in Java and their effect on the accessibility of methods.

Option A: This option is incorrect. There should be no compile-time errors in the code as all the methods in the interface are correctly defined.

Option B: This option is incorrect. The protected access modifier can be used in interface methods, so there should be no compile-time error at line 3.

Option C: This option is incorrect. The default access modifier can be used in interface methods, so there should be no compile-time error at line 1.

Option D: This option is correct. The private access modifier cannot be used in interface methods as they are implicitly abstract and intended to be implemented by other classes. Thus, there is a compile-time error at line 4. Additionally, the protected access modifier can be used in interface methods, but it may cause issues with implementation, so it is not recommended.

Option E: This option is incorrect. The correct answer is option D.

Therefore, the answer is: D. compiletime error at lines 3,4.

Multiple choice technology programming languages
  1. compiletime error at lines 1,2,3,4,5

  2. compiletime error at lines 2,3,4,5

  3. compiletime error at lines 2,3,4

  4. prints 3

  5. None of the above

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

In Java, access modifiers (private, protected, public) cannot be used for local variables inside a method. These modifiers only apply to class members (fields and methods). Therefore lines 2, 3, and 4 are invalid. Line 5 is also invalid because it tries to access these non-existent local variables.

Multiple choice technology programming languages
  1. Prints: ABC

  2. Prints BC and Runtime Exception

  3. Prints: BCD

  4. Runtime Exception

  5. None of the above

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

The execution arguments passed are A, B, and C, corresponding to indices 0, 1, and 2. Printing a1[1] + a1[2] outputs BC, but accessing a1[3] subsequently throws an ArrayIndexOutOfBoundsException at runtime.

Multiple choice technology programming languages
  1. prints 1,2

  2. prints 2,0

  3. prints 2,2

  4. compile time error

  5. Noneofthe above

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

In the main method, m1() is called. Inside m1(), x is a local variable with value 1. When m2(x) is called, Java passes x by value, so m2 receives a copy. In m2, this copy becomes 2 (x*2), but the original x in m1 remains 1. Static variable s is set to 2. Output: '1' from m1's println, then '2' from main's println of s.

Multiple choice technology programming languages
  1. prints one two three

  2. prints one

  3. compile time error

  4. Runtime exception

  5. None of the above

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

In Java switch statements, when a case matches, execution continues through all subsequent cases unless a break statement is encountered. This is called fallthrough. When i1=1, case 1 matches and prints 'one', then execution falls through to case 2 which prints 'two', then to case 3 which prints 'three'.

Multiple choice technology programming languages
  1. The output is “Equal”

  2. The output in “Not Equal”

  3. An error at " if (x = y)" causes compilation to fall.

  4. The program executes but no output is show on console.

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

The code uses assignment (=) instead of comparison (==) inside the if statement: if (x = y). In Java, this is a compilation error because the if condition requires a boolean expression, but assignment returns an int value. Java does not allow numeric types in conditional contexts.

Multiple choice technology programming languages
  1. Error Variable i may not have been initialized

  2. null

  3. 1

  4. 0

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

In Java, static (class) variables are automatically initialized to default values. For int, the default value is 0. Therefore, 'i' will be 0 when printed, and there will be no compilation error about uninitialized variables.

Multiple choice technology programming languages
  1. Error: anar is referenced before it is initialized

  2. null

  3. 0

  4. 5

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

In Java, when you create a new int array, all elements are automatically initialized to 0. The code creates an int array of size 5 and prints the first element anar[0], which will be 0.