What is the output of the following code?
class EJavaGuruArray { public static void main(String args[]) { int[] arr = new int[5]; byte b = 4; char c = 'c'; long longVar = 10; arr[0] = b; arr[1] = c; arr[3] = longVar; System.out.println(arr[0] + arr[1] + arr[2] + arr[3]); } }
- 4c010
- 4c10
- 113
- 103
- Compilation error
What is the output of the following code?
class EJavaGuruArray2 { public static void main(String args[]) { int[] arr1; int[] arr2 = new int[3]; char[] arr3 = {'a', 'b'}; arr1 = arr2; arr1 = arr3; System.out.println(arr1[0] + ":" + arr1[1]); } }
- 0:0
- a:b
- 0:b
- a:0
- Compilation error
Which of the following are valid lines of code to define a multidimensional int array?
- int[][] array1 = {{1, 2, 3}, {}, {1, 2,3, 4, 5}};
- int[][] array2 = new array() {{1, 2, 3}, {}, {1, 2,3, 4, 5}};
- int[][] array3 = {1, 2, 3}, {0}, {1, 2,3, 4, 5};
- int[][] array4 = new int[2][];
Which of the following statements are correct?
- The following code executes without an error or exception:
ArrayList<Long> lst = new ArrayList<>(); lst.add(10);- Because ArrayList stores only objects, you can’t pass an element of an ArrayList to a switch construct.
- Calling clear() or remove() on an ArrayList will remove all its elements.
- If you frequently add elements to an ArrayList, specifying a larger capacity will improve the code efficiency.
- Calling the method clone() on an ArrayList creates its shallow copy; that is, it doesn’t clone the individual list elements.
Which of the following statements are correct?
- An ArrayList offers a resizable array, which is easily managed using the methods it provides. You can add and remove elements from an ArrayList.
- Values stored by an ArrayList can be modified.
- You can iterate through elements of an ArrayList using a for loop, Iterator, or ListIterator.
- An ArrayList requires you to specify the total number of elements before you can store any elements in it.
- An ArrayList can store any type of object.
What is the output of the following code?
import java.util.*; // line 1 class EJavaGuruArrayList { // line 2 public static void main(String args[]) { // line 3 ArrayList<String> ejg = new ArrayList<>(); // line 4 ejg.add("One"); // line 5 ejg.add("Two"); // line 6 System.out.println(ejg.contains(new String("One"))); // line 7 System.out.println(ejg.indexOf("Two")); // line 8 ejg.clear(); // line 9 System.out.println(ejg); // line 10 System.out.println(ejg.get(1)); // line 11 } // line 12 } // line 13
- Line 7 prints true.
- Line 7 prints false.
- Line 8 prints -1.
- Line 8 prints 1.
- Line 9 removes all elements of the list ejg.
- Line 9 sets the list ejg to null.
- Line 10 prints null.
- Line 10 prints [].
- Line 10 prints a value similar to ArrayList@16356.
- Line 11 throws an exception.
- Line 11 prints null.
What is the output of the following code?
class EJavaGuruString { public static void main(String args[]) { String ejg1 = new String("E Java"); String ejg2 = new String("E Java"); String ejg3 = "E Java"; String ejg4 = "E Java"; do System.out.println(ejg1.equals(ejg2)); while (ejg3 == ejg4); } }
- true printed once
- false printed once
- true printed in an infinite loop
- false printed in an infinite loop
What is the output of the following code?
class EJavaGuruString2 { public static void main(String args[]) { String ejg = "game".replace('a', 'Z').trim().concat("Aa"); ejg.substring(0, 2); System.out.println(ejg); } }
- gZmeAZ
- gZmeAa
- gZm
- gZ
- game
What is the output of the following code?
class EJavaGuruString2 { public static void main(String args[]) { String ejg = "game"; ejg.replace('a', 'Z').trim().concat("Aa"); ejg.substring(0, 2); System.out.println(ejg); } }
- gZmeAZ
- gZmeAa
- gZm
- gZ
- game
What is the output of the following code?
class EJavaGuruStringBuilder { public static void main(String args[]) { StringBuilder ejg = new StringBuilder(10 + 2 + "SUN" + 4 + 5); ejg.append(ejg.delete(3, 6)); System.out.println(ejg); } }
- 12S512S5
- 12S12S
- 1025102S
- Runtime exception
What is the output of the following code?
class EJavaGuruStringBuilder2 { public static void main(String args[]) { StringBuilder sb1 = new StringBuilder("123456"); sb1.subSequence(2, 4); sb1.deleteCharAt(3); sb1.reverse(); System.out.println(sb1); } }
- 521
- Runtime exception
- 65321
- 65431
What is the output of the following code?
String printDate = LocalDate.parse("2057-08-11") .format(DateTimeFormatter.ISO_DATE_TIME); System.out.println(printDate);
- August 11, 2057T00:00
- Saturday Aug 11,2057T00:00
- 08-11-2057T00:00:00
- Compilation error
- Runtime exception
3.145.109.234