0

programming languages Online Quiz - 96

Description: programming languages Online Quiz - 96
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

"01 WS-VAR1 PIC X(10) VALUE 'ABCDEFGHIJ'. 01 WS-VAR2 REDEFINES WS-VAR1 PIC 9(5) VALUE '12345' DISPLAY WS-VAR1 WS-VAR2. What will be the result?"

  1. ABCDEFGHIJ 12345

  2. Data Exception error

  3. Compilation error

  4. 12345FGHIJ 12345


Correct Option: C

What is the maximum length of a field you can define using COMP-1?

  1. 10

  2. 18

  3. 17

  4. 12


Correct Option: A

"05 X PIC 99 VALUE 10. SUBTRACT 20 FROM X. DISPLAY X The result would be?"

  1. 1}

  2. It will give error

  3. 10

  4. -10


Correct Option: C

"77 WS-AMT PIC ZZZ999. ADD 100 TO WS-AMT WILL RESULT IN?"

  1. COMPILATION ERROR

  2. SOC7

  3. WS-AMT+100

  4. SOC4


Correct Option: A

"What will be the output of the following snippet: MOVE ZERO TO WS-COUNT IF WS-COUNT = 0 CONTINUE END-IF ADD +1 TO WS-COUNT. DISPLAY 'VALUE OF WS-COUNT: ' WS-COUNT "

  1. VALUE OF WS-COUNT: 0

  2. VALUE OF WS-COUNT: 1

  3. Compile error

  4. None of the above


Correct Option: A

"What will be the output of the following snippet: MOVE ZERO TO WS-COUNT IF WS-COUNT = 0 NEXT SENTENCE END-IF ADD +1 TO WS-COUNT. DISPLAY 'VALUE OF WS-COUNT: ' WS-COUNT "

  1. VALUE OF WS-COUNT: 0

  2. VALUE OF WS-COUNT: 1

  3. Compile error

  4. None of the above


Correct Option: A

The "switch" selection structure must end with the default case.

  1. True

  2. False


Correct Option: A

What will happen when you attempt to compile and run the following code? int Output = 10; boolean b1 = false; if((b1 == true) && ((Output += 10) == 20)) { System.out.println("We are equal " + Output); } else { System.out.println("Not equal! " + Output); }

  1. Compilation error, attempting to perform binary comparison on logical data type.

  2. Compilation and output of "We are equal 10".

  3. Compilation and output of "Not equal! 20".

  4. Compilation and output of "Not equal! 10".


Correct Option: D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) Compilation error, attempting to perform binary comparison on logical data type - This option is incorrect. The code does not attempt to perform a binary comparison on a logical data type. It uses logical operators (&&) to combine multiple conditions.

Option B) Compilation and output of "We are equal 10" - This option is incorrect. The condition (b1 == true) && ((Output += 10) == 20) evaluates to false since b1 is false. Therefore, the code will not enter the if block, and the statement System.out.println("We are equal " + Output); will not be executed.

Option C) Compilation and output of "Not equal! 20" - This option is incorrect. The condition (b1 == true) && ((Output += 10) == 20) evaluates to false since b1 is false. Therefore, the code will enter the else block, and the statement System.out.println("Not equal! " + Output); will be executed. However, the value of Output is still 10, as the statement Output += 10 is not executed.

Option D) Compilation and output of "Not equal! 10" - This option is correct. The condition (b1 == true) && ((Output += 10) == 20) evaluates to false since b1 is false. Therefore, the code will enter the else block, and the statement System.out.println("Not equal! " + Output); will be executed. The value of Output remains 10.

The correct answer is Option D. This option is correct because the code will output "Not equal! 10" to the console.

What results from attempting to compile and run the following code? public class Ternary { public static void main(String args[]) { int a = 5; System.out.println("Value is - " + ((a < 5) ? 9.9 : 9)); } }

  1. prints: Value is - 9

  2. prints: Value is - 5

  3. Compilation error

  4. None of these


Correct Option: D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) prints: Value is - 9 - This option is incorrect because the code will not print "Value is - 9". Instead, it will print "Value is - 9.0" because the expression (a &lt; 5) ? 9.9 : 9 evaluates to 9.9, which is a double value.

Option B) prints: Value is - 5 - This option is incorrect because the code will not print "Value is - 5". The value of the variable a is 5, but the ternary expression (a &lt; 5) ? 9.9 : 9 evaluates to 9.9, not 5.

Option C) Compilation error - This option is incorrect because the code will compile successfully without any errors. The code uses valid Java syntax.

Option D) None of these - This option is correct because the code will print "Value is - 9.0". The ternary expression (a &lt; 5) ? 9.9 : 9 evaluates to 9.9, which is a double value. The output will include the decimal point and ".0" because it is a double value.

Therefore, the correct answer is D) None of these.

What is the result when you compile and run the following code? public class Test { public void method() { for(int i = 0; i < 3; i++) { System.out.print(i); } System.out.print(i); } }

  1. 0122

  2. 0123

  3. Compilation error

  4. None of these


Correct Option: C

What will be the output on compiling/running the following code? public class MyThread implements Runnable { String myString = "Yes "; public void run() { this.myString = "No "; } public static void main(String[] args) { MyThread t = new MyThread(); new Thread(t).start(); for (int i=0; i < 10; i++) System.out.print(t.myString); } }

  1. Compilation Error

  2. Prints : Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes and so on.

  3. Prints : No No No No No No No No No No and so on.

  4. Prints : Yes No Yes No Yes No Yes No Yes No and so on.

  5. The Output cannot be determined.


Correct Option: E

we Can create multiple objects of a single class.

  1. True

  2. False


Correct Option: A

The modulus operator (%) in Java can be used only with variables of integer type.

  1. True

  2. False


Correct Option: B

AI Explanation

To answer this question, you need to understand the modulus operator (%) in Java and the types of variables it can be used with.

The modulus operator (%) in Java calculates the remainder of one number divided by another. While it is commonly used with integer types, it can also be used with other data types such as floating-point numbers (e.g., double and float).

So, the statement "The modulus operator (%) in Java can be used only with variables of integer type" is incorrect.

Let's go through each option to understand why it is correct or incorrect:

Option A) True - This option is incorrect because the modulus operator (%) in Java can be used with variables of other types, not just integer types.

Option B) False - This option is correct because the statement "The modulus operator (%) in Java can be used only with variables of integer type" is false.

The correct answer is B) False.

Declarations must appear at the start of the body of a Java method.

  1. True

  2. False


Correct Option: B

AI Explanation

To answer this question, we need to understand the concept of variable declarations in Java methods.

In Java, variable declarations can appear anywhere within the body of a method, not just at the start. This means that variables can be declared and initialized at any point within the method's block.

Therefore, the correct answer is:

B) False - Declarations do not need to appear at the start of the body of a Java method. They can be placed anywhere within the method's block.

Whenever the "&&" operator is used, such as in: exp1 && exp2 where exp1 and exp2 are boolean expressions, both the boolean expressions are not always evaluated.

  1. True

  2. False


Correct Option: A

What is displayed when the following code is compiled and executed? String s1 = new String("Test"); String s2 = new String("Test"); if (s1==s2) System.out.println("Same"); if (s1.equals(s2)) System.out.println("Equals");

  1. Same Equals

  2. Equals

  3. Same

  4. The code compiles, but nothing is displayed upon execution.

  5. The code fails to compile.


Correct Option: B

1) What will be the output of the following program?package chapters.chap02;public class Chap02 { public static void main(String[] args) { for (int i=0; i&lt;5; i++){ switch (i){ case 0: System.out.println(&quot;0&quot;); ++i; break; case -1: System.out.println(&quot;-1&quot;); break; case 2: System.out.println(&quot;2&quot;); i++; case 4: System.out.println(&quot;4&quot;); break; } } }}

  1. The program will not stop and it will run recursively upon execution

  2. The program will output '0 2 5 5'.

  3. The program will output '0 2 4 4'.

  4. The program will output '02 4 5'.


Correct Option: C

2) What will be the output of the following program when it is made to run with the options "java scjp5_0.chap07.Ques01 1"package scjp5_0.chap07;public class Ques01 { public static void main(String[] args) { for (int i = 0; i < 2; i ++){ try{ System.out.println(args[i]); }catch(Exception e){} } }}

  1. The program will output 'scjp5_0.chap07.Ques01 1'.

  2. The program will output 1.

  3. The program will output '1' and then will raise an ArrayIndexOutOfBoundsException.

  4. The program won't print anything but will raise an ArrayIndexOutOfBoundsException at run-time.


Correct Option: B

3) How can you call one constructor from another if a class has multiple constructors

  1. Cant do

  2. use this ()

  3. new keyword

  4. using objectname


Correct Option: B
- Hide questions