Tag: programming languages

Questions Related to programming languages

public class xyz { public static void main(String args[]) { for(int i = 0; i < 2; i++) { for(int j = 2; j>= 0; j--) { if(i == j) break; System.out.println("i=" + i + " j="+j); } } } } A) i=0 j=0 B) i=0 j=1 C) i=0 j=2 D) i=1 j=0 E) i=1 j=1 F) i=1 j=2 G) i=2 j=0 H) i=2 j=1 I) i=2 j=2

  1. B,C

  2. A,I,F

  3. B,C,F

  4. None of the above


Correct Option: C

Select the one correct answer. Which method defined in Integer class can be used to convert an Integer object to primitive int type. A) valueOf B) intValue C) getInt D) getInteger

  1. A

  2. C

  3. D

  4. None of the Above


Correct Option: D
  1. D

  2. E

  3. A

  4. Both D and E


Correct Option: D
Explanation:

To solve this question, the user must understand the concepts of try-catch blocks and the order of exception handling.

The code first initializes two integer variables, i and j, both with the value 1. It then enters a try block where it increments i by 1 and decrements j by 1. If i and j are equal, it increments i by 1 again. However, this condition is not met, so the code skips over the try block and proceeds to the finally block, where it prints out 3. It then prints out 4.

The correct answer is D) Both D and E, because the code will output 3 and 4. The try block does not throw any exceptions, so none of the catch blocks are executed. The finally block is always executed, regardless of whether an exception is thrown or not. Therefore, the output will be 3 (from the finally block) and 4 (from the last print statement).

Is the following statement true or false. As the toString method is defined in the Object class, System.out.println can be used to print any object.

  1. True

  2. False


Correct Option: A
  1. if((i == 0) || (j/i == 1))

  2. if((i == 0) | (j/i == 1))

  3. if((i != 0) && (j/i == 1))

  4. if((i != 0) & (j/i == 1))


Correct Option: B,D

The maximum combined length of the command line arguments including the spaces between adjacent arguments is

  1. 128 characters

  2. 256 characters

  3. 67 characters

  4. It may vary from one operating system to another


Correct Option: D