Java MCQ – Multiple Choice Questions and Answers – Strings – Part 1
This collection of Java Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Java Strings”.
1. Which of the following class is the superclass of String and StringBuffer class?
A ArrayList
B java.util
C java.lang
D java.string
2. Which of the following operators, we can use to concatenate two String?
A ||
B &
C +=
D +
3. String in Java is a _________?
A object
B class
C reference
D array of character
4. What is the output of the following code?
public class Q4 { public static void main(String []args) { String s1 = new String("Ali"); String s2 = new String("Alis"); System.out.println(s1 = s2); } }
A true
B false
C Ali
D Alis
5. Which of the following method is used to get the length of a String object?
A getSize()
B Sizeof()
C len()
D length()
6. Which of the following method is used to get the character at specified index?
A getChar()
B Charat()
C charat()
D charAt()
7. What is the output of the following code?
public class Q7 { public static void main(String []args) { String s1 = new String("Hello"); String s2 = new String(s1); System.out.println(s1 == s2); } }
A Hello
B true
C false
D Error
8. Which of the following method is used to test tow strings for equality?
A checkEqual()
B eq()
C equals()
D equal()
9. What is the output of the following code?
public class Q8 { public static void main(String []args) { String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1.equals(s2)); System.out.println(s1 == s2); } }
A false true
B true false
C false false
D true true
10. Which of the following affirmations are incorrect?
A Each string is an object of class String
B Strings in java are changeable
C String is a class
D Java defines a fellow class of String, called StringBuffer, which enables string to be modified