• Courses
  • Tutorials
  • Practice
Switch to Dark Mode

Java String Basics

Here are 10 essential multiple-choice questions on Java String Basics, covering key concepts.


Last Updated : Mar 27, 2025
Discuss
Comments

Question 1

What is the correct way to declare a String in Java?

  • A

    String str = 'Hello';


  • B

    String str = new String("Hello");

  • C

    String str = String("Hello");

  • D

    String str = Hello;

Question 2

Why are Strings immutable in Java?


  • A

    To improve performance


  • B

    To allow modifications in-place

  • C

    To ensure thread safety and security

  • D

    Because Java does not support mutable objects

Question 3

What will be the output of the following code?

Java
String s1 = "Java";
String s2 = "Java";
System.out.println(s1 == s2);
  • A

    true

  • B

    false

  • C

    Compilation Error

  • D

    Runtime Exception

Question 4

What will be the output of the following code?

Java
String s1 = new String("Java");
String s2 = new String("Java");
System.out.println(s1 == s2);
  • A

    true

  • B

    false

  • C

    Compilation Error


  • D

    Runtime Exception

Question 5

Which method is used to concatenate two Strings in Java?

  • A

    combine()

  • B

    merge()

  • C

    concat()

  • D

    append()

Question 6

What will be the output of the following code?

Java
String s = "Hello";
s.concat(" World");
System.out.println(s);
  • A

    Hello World

  • B

    Hello

  • C

    World

  • D

    Compilation Error

Question 7

How can you make String mutable in Java?

  • A

    Using StringBuilder or StringBuffer

  • B

    Using final keyword

  • C

    By modifying the existing String object

  • D

    By using String.concat()

Question 8

What will be the output of the following code?

Java
String s1 = "Hello";
String s2 = s1.concat(" World");
System.out.println(s2);
  • A

    Hello

  • B

    World

  • C

    Hello World

  • D

    Compilation Error

Question 9

How does the intern() method affect Strings in Java?

  • A

    It removes duplicate Strings from memory

  • B

    It ensures that the String is stored in the String Pool

  • C

    It modifies the original String

  • D

    It converts the String into a StringBuffer

Question 10

What is the advantage of using String over StringBuilder in multi-threaded applications?

  • A

    String is faster than StringBuilder


  • B

    String is synchronized

  • C

    String is immutable and therefore thread-safe

  • D

    String can be modified in place


There are 10 questions to complete.

Take a part in the ongoing discussion