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
  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

10 What modifiers would be legal at XX in the following code? public class MyClass1 { public static void main(String argv[]){ } /*Modifier at XX */ class MyInner {} }

  1. a. public

  2. b. private

  3. c. static

  4. d. friend


Correct Option: A,B

AI Explanation

To determine which modifiers would be legal at XX in the given code, let's go through each option:

Option A) Public - This option is correct because the "public" modifier can be used for nested classes. It allows the class to be accessed from any other class.

Option B) Private - This option is correct because the "private" modifier can also be used for nested classes. It restricts the visibility of the class to only within the enclosing class.

Option C) Static - This option is incorrect because the "static" modifier cannot be used for nested classes. It can only be used for top-level classes, interfaces, and inner interfaces.

Option D) Friend - This option is incorrect because the "friend" modifier does not exist in Java. It is a modifier used in other programming languages like C++.

Therefore, the correct modifiers that would be legal at XX in the given code are A) Public and B) Private.