MCQ on String for concepts and interview preparation QAE - SDET - AUTOMATION QA 2022
1. What is the output for below?
String str1 = "test";
String str2 = "one";
String str3 = str1.concat(str2);
Ans:
a) testone
b) test
c) one
d) Let me check in IDE :)
2. What is the output for below?
String str1 = "test";
String str2 = "test";
String str3 = new String("test");
System.out.println(str1.equals(str2));
System.out.println(str1.equals(str3));
Ans:
a) true,true
b) false, true
c) false, false
d) Let me check in IDE :)
3. What is the output for below?
String str1 = "test";
String str2 = "test";
String str3 = new String("test");
System.out.println(str1==str2));
System.out.println(str1==str3);
a) true, true
b) true, false
c) false, true
d) false, false
4. What is the output for below?
String str = "test";
System.out.println(str1.charAt(2));
a) s
b) e
c) error
d) es
5. What is the output for below?
System.out.println("012301230123".replace(55, "45"));
System.out.println("012301230123".replace("01", "45"));
a) compile error, 452345234523
b) 452345234523, 452345234523
c) error, error
d) Let me check in IDE :)
6. What is the output for below?
System.out.println("tes".substring(3));
System.out.println("test".substring(3));
a) error, error
b) error, t
c) , t
d) t, t
7. How many ways we can create String Object in Java?
a) String s = "abc"; String s1 = new String("abc");
b) Literal, Keyword
c) Both A and B
d) Not sure
8. Is String thread safe?
a) true
b) false
c) Not sure
9. What is the output for below?
String str8 = new StringBuilder("test").reverse().toString();
System.out.println(str8);
a) test
b) tset
c) Not sure
10. Which one is thread safe: StringBuffer or StringBuffer ?
a) Both
b) StringBuffer
c) StringBuilder
d) None of the options
Below are the answers for all the questions on STRING:
1. a)testone
2. a)true,true
3. b)true, false
4. a)S
5. a) compile error, 452345234523
6. c) , t
7. c) Both A and B
8. a) true
9. b) tset
No comments:
Post a Comment
Add ur comment here!!!