Arrays & Strings

6.What is the output of the following Java code?
public class Main { public static void main(String[] args) { String s1 = "Java"; String s2 = "Java"; System.out.println(s1 == s2); } }
  • A. true
  • B. false
  • C. Compilation error
  • D. Runtime exception

true

true

7.What is the output of the following code?
public class Main { public static void main(String[] args) { String s1 = new String("Hello"); String s2 = new String("Hello"); System.out.println(s1 == s2); } }
  • A. true
  • B. false
  • C. Compilation error
  • D. Runtime exception

false

false

8.Which method is used to compare two strings in Java based on content?
  • A. ==
  • B. equals()
  • C. compareTo()
  • D. match()

equals()

equals()

9.What will be the output of the following code?
public class Main { public static void main(String[] args) { String s1 = "Hello"; String s2 = "hello"; System.out.println(s1.equalsIgnoreCase(s2)); } }
  • A. Runtime exception
  • B. Compilation error
  • C. false
  • D. true

true

true

10.What will be the output of the following code? java Copy Edit
public class Main { public static void main(String[] args) { String s = "Java Programming"; System.out.println(s.substring(5, 11)); } }
  • A. Java P
  • B. Progra
  • C. Programm
  • D. Compilation error

Progra

Progra