Tag: programming languages

Questions Related to programming languages

  1. a. int arr[][] = new int[5][5];

  2. b. int []arr[] = new int[5][5];

  3. c. int[][] arr = new int[5][5];

  4. d. int[] arr = new int[5][];

  5. e. int[] arr = new int[][5];


Correct Option: A,B
  1. a. String str[];

  2. b. String str[5] = new String[5];

  3. c. String str[] = new String[] {"string1", "string2", "string3", "string4", "string5

  4. d. String str[] = {"string1","string2", "string3", "string4", "string5"};


Correct Option: A,C,D

6 What will happen when you compile the following code? 1. package sources; 2. public class firstjava { 3. public static void main(String args[]) 4. { 5. private int a[] ={ 4, 4 }; 6. public int b=1; 7. a[b]=b=0; 8. System.out.println("value of b & a[0] & a[1]" + b + a[0] +a[1]); 9. } 10. }

    1. Compilation error at line 2
    1. Runtime error at line 7.
    1. Compilation error at Line 7
    1. Compiles and prints 0 0 4
    1. Compiles and prints 0 4 0

Correct Option: A
  1. a. Bic

  2. b. ic

  3. c. icy

  4. d. error: no method matching substring(int,char)


Correct Option: B
Explanation:

To solve this question, the user needs to understand the concept of substring and character indices.

The given code creates a string object s with value "Bicycle". The variables iBegin and iEnd have been assigned the values 1 and 3, respectively. The substring method is then called on the string object s with two arguments: iBegin and iEnd. The substring method extracts a portion of the string starting at the index specified by iBegin and ending at the index specified by iEnd-1.

Option A is incorrect because the substring method with arguments (1,3) extracts the portion of the string starting at index 1 and ending at index 2. Thus, the output is "Bi".

Option B is correct because the substring method with arguments (1,3) extracts the portion of the string starting at index 1 and ending at index 2. Thus, the output is "ic".

Option C is incorrect because the substring method with arguments (1,3) extracts the portion of the string starting at index 1 and ending at index 2. Thus, the output is "ic", not "icy".

Option D is incorrect because the syntax of the substring method is correct, and there is a matching method signature that takes an int and a char.

Therefore, the answer is:

The Answer is: B. ic