AllInfoHub Logo

AllInfoHub – MCQ Practice

Variables and Data Types – Multiple Choice Questions (MCQs)

  1. 37. What is the purpose of the `String` class in Java?

    • A. To represent single characters
    • B. To represent sequences of characters
    • C. To represent numeric values
    • D. To represent boolean values
  2. 38. Is `String` a primitive or reference data type in Java?

    • A. Primitive
    • B. Reference
    • C. Depends on the JVM
    • D. Neither
  3. 39. Are Strings mutable or immutable in Java?

    • A. Mutable
    • B. Immutable
    • C. Depends on the JVM
    • D. Neither
  4. 40. How do you declare and initialize a String variable in Java?

    • A. String s = 'hello';
    • B. string s = "hello";
    • C. String s = "hello";
    • D. s String = "hello";
  5. 41. What is string concatenation in Java?

    • A. Joining two or more strings together
    • B. Converting a string to uppercase
    • C. Converting a string to lowercase
    • D. Finding the length of a string
  6. 42. Which operator is used for string concatenation in Java?

    • A. +
    • B. &
    • C. |
    • D. .
  7. 43. What will be the output of `Hello" + "World"` in Java?"

    • A. HelloWorld
    • B. Hello World
    • C. Hello World
    • D. Error
  8. 44. What is the purpose of the `StringBuilder` class in Java?

    • A. To represent immutable strings
    • B. To efficiently build and modify strings
    • C. To format strings
    • D. To compare strings
  9. 45. What is the purpose of the `StringBuffer` class in Java?

    • A. To represent immutable strings
    • B. To efficiently build and modify strings in a thread-safe manner
    • C. To format strings
    • D. To compare strings
  10. 46. What is an array in Java?

    • A. A single variable that can store multiple values of different data types
    • B. A collection of elements of the same data type stored in contiguous memory locations
    • C. A class that represents a list of objects
    • D. A primitive data type
  11. 47. How do you declare an integer array of size 5 in Java?

    • A. int array[5];
    • B. int[] array = new int[5];
    • C. array int[5];
    • D. array = int[5];
  12. 48. How do you access the first element of an array named `myArray` in Java?

    • A. myArray[0]
    • B. myArray(0)
    • C. myArray.get(0)
    • D. myArray.first()