Java String Handling Test | Core Java Topical Test (Series 2)
Finish Quiz
0 of 19 questions completed
Questions:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
Information
Java String Handling Test Series 2 | Core Java Topical Test. Java String Handlingย Test Quiz 2, Coreย javaย Topicalย Testsย have the best questions to make you understand the topic well. … Thisย Testย will coverย String Handlingย from basic to advanced level..Free Java String Handlingย Quiz, Online Java, online Test Quiz 2. Java String Handlingย Test Quiz 2ย Question and Answers 2025 is available for all users in Free . Now take Java online Test Quiz 2 in free from below…. Java String Handlingย Quiz 2ย Free Mock Testย 2025.ย Java String Handlingย Test Quiz 2ย Question and Answers in PDF.ย The Java online mock test paper is free for all students.ย Java String Handlingย Testย is very useful for exam preparation and getting for Rank. Java String Handlingย Test Quiz 2ย Question and Answers in English. Java String Handlingย Mock test forย ย topic via String Handlingย Mode.ย Here we are providingย Java String Handlingย Mock Test in Englishย Now Test your self for โJava String Handlingย Testย in Englishโ Exam by using below quizโฆ
This paper has 20ย questions.
Time allowed is 25 minutes.
The Java String Handlingย Mock Test ย is Very helpful for all students.ย Now Scroll down below n click on โStart Quizโ or โStart Testโ andย Test yourself.
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
Results
0 of 19 questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 points, (0)
Average score |
|
Your score |
|
Categories
- Not categorized 0%
Pos. | Name | Entered on | Points | Result |
---|---|---|---|---|
Table is loading | ||||
No data available | ||||
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- Answered
- Review
-
Question 1 of 19
1. Question
What is output?
- publicย classย Test15{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย publicย staticย voidย method(StringBufferย newSb){
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย newSb.append(”ย Added”);ย ย ย ย ย ย ย ย ย ย ย ย ย //Lineย 3ย
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย newSb=ย newย StringBuffer(“Hai”);ย ย ย //Lineย 4ย
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย publicย staticย voidย main(Stringย a[]){
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย StringBufferย sbย =ย newย StringBuffer(“Stringย Buffer”);
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย method(sb);
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย System.out.println(sb);
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- }
Choose the one below:
Correct
As StringBuffer is mutable class when newSb.append(” Added”) is executed, it appends the string value to actual object which is referred by newSb and sb reference variables. At Line 4 new StringBuffer object is created and refrenced by newSb but sb still refer to the actual object and the above code snippet results to “String Buffer Added“.
Incorrect
As StringBuffer is mutable class when newSb.append(” Added”) is executed, it appends the string value to actual object which is referred by newSb and sb reference variables. At Line 4 new StringBuffer object is created and refrenced by newSb but sb still refer to the actual object and the above code snippet results to “String Buffer Added“.
-
Question 2 of 19
2. Question
What will be the output?
- publicย classย Test2{
- ย ย ย ย ย ย ย ย ย ย ย ย staticย voidย method(Stringย str){
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย System.out.println(“String”);
- ย ย ย ย ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย ย ย ย ย ย publicย staticย voidย main(Stringย args[]){
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย method(null);
- ย ย ย ย ย ย ย ย ย ย ย ย }
- }
Choose the one below:
Correct
static method is associate with class not with object. Hence the above code snippet results “String” as output.
Incorrect
static method is associate with class not with object. Hence the above code snippet results “String” as output.
-
Question 3 of 19
3. Question
Which of the following methods are methods of the String class?
Correct
replace() method is available in String class and it is returns a new string resulting from replacing all occurrences of old character in this string with new character.
Incorrect
replace() method is available in String class and it is returns a new string resulting from replacing all occurrences of old character in this string with new character.
-
Question 4 of 19
4. Question
Is String a wrapper class?
Correct
String is not wrapper class. In Java, Wrapper class is defined as class which converts and store equivalet primitive type. For example :- Integer, Character
Incorrect
String is not wrapper class. In Java, Wrapper class is defined as class which converts and store equivalet primitive type. For example :- Integer, Character
-
Question 5 of 19
5. Question
What will be the output?
System.out.println(“john” == new String(“john”));
System.out.println(“john”.equals(“john”));
System.out.println(“john” == “john”);
System.out.println(new String(“john”)==new String(“john”));Correct
“john” == new String(“john”) produces false as “john” is created in string pool and new String(“john”) at heap and == operator compares object reference.
“john”.equals(“john”) produces true as equals() method compares content of object.
“john” == “john” produces true as “john” is created in String pool and refer to same object.
new String(“john”)==new String(“john”) creates two string in heap and == checks reference of both objects and returns false.
Incorrect
“john” == new String(“john”) produces false as “john” is created in string pool and new String(“john”) at heap and == operator compares object reference.
“john”.equals(“john”) produces true as equals() method compares content of object.
“john” == “john” produces true as “john” is created in String pool and refer to same object.
new String(“john”)==new String(“john”) creates two string in heap and == checks reference of both objects and returns false.
-
Question 6 of 19
6. Question
Examine the following code
String str = null;
boolean bValue = str instanceof String;What value is placed in bValue?
Correct
instanceof is used to check if an object is an instance of a class, an instance of a subclass, or an instance of a class that implements a particular interface. In the above code snippet reference variable str is null. Hence the output is FALSE.
Incorrect
instanceof is used to check if an object is an instance of a class, an instance of a subclass, or an instance of a class that implements a particular interface. In the above code snippet reference variable str is null. Hence the output is FALSE.
-
Question 7 of 19
7. Question
What is the output of below code snippet?
if( new String(“ModernPathshala”).trim() == new String(“ModernPathshala”) )
ย ย ย ย System.out.println(“Equal”);
else
ย ย ย ย System.out.println(“Not Equal”);Correct
The above code snippet results as Not Equal as an output because reference of both string are not same.
Incorrect
The above code snippet results as Not Equal as an output because reference of both string are not same.
-
Question 8 of 19
8. Question
What will the following program print when run?
- publicย classย Searchย {
- ย ย ย ย publicย staticย voidย main(String[]ย args)ย {
- ย ย ย ย ย ย ย ย Stringย sย =ย “Contentment!”;
- ย ย ย ย ย ย ย ย intย middleย =ย s.length()/2;
- ย ย ย ย ย ย ย ย Stringย ntย =ย s.substring(middle-1,ย middle+1);
- ย ย ย ย ย ย ย ย System.out.println(s.lastIndexOf(nt,ย middle));
- ย ย ย ย }
- }
Correct
s.length()/2 returns 6
s.substring(middle-1, middle+1) returns nt.
s.lastIndexOf(nt, middle) searches String value “nt” from middle i.e 5th index of String s.
Output:- 5Incorrect
s.length()/2 returns 6
s.substring(middle-1, middle+1) returns nt.
s.lastIndexOf(nt, middle) searches String value “nt” from middle i.e 5th index of String s.
Output:- 5 -
Question 9 of 19
9. Question
Which one of the following is not legal?
Correct
Option System.out.println(“st” + new String(โeโ + โpโ)); is invalid as ‘e’+’p’ results to an integer value and String class does not have any constructor to create String using integer value.
Incorrect
Option System.out.println(“st” + new String(โeโ + โpโ)); is invalid as ‘e’+’p’ results to an integer value and String class does not have any constructor to create String using integer value.
-
Question 10 of 19
10. Question
What will be the result of attempting to compile and run the following code?
- publicย classย TestStringOperationย {
- ย ย ย ย publicย staticย voidย main(String[]ย args)ย {
- ย ย ย ย ย ย ย ย Stringย str1ย =ย newย String(“java”);
- ย ย ย ย ย ย ย ย str1.concat(”ย world”);
- ย ย ย ย ย ย ย ย StringBufferย strBuf1ย =ย newย StringBuffer(”ย magazine”);
- ย ย ย ย ย ย ย ย strBuf1.append(”ย article”);
- ย ย ย ย ย ย ย ย System.out.println(str1ย +ย strBuf1);
- ย ย ย ย }
- }
Correct
concat() method returns a new String with the value of the String passed into the methodand append it to the end of the String used to invoke this method. So value of str1 remains “java” after executing str1.concat(” world”); line. Value of strBuf1 becomes “magazine article” after executing strBuf1.append(” article”); line. Hence System.out.println(str1 + strBuf1); results “java magazine article” as an output.
Incorrect
concat() method returns a new String with the value of the String passed into the methodand append it to the end of the String used to invoke this method. So value of str1 remains “java” after executing str1.concat(” world”); line. Value of strBuf1 becomes “magazine article” after executing strBuf1.append(” article”); line. Hence System.out.println(str1 + strBuf1); results “java magazine article” as an output.
-
Question 11 of 19
11. Question
What results would print from the following code snippet:
System.out.println(“ABCDE “.valueOf(98765));?Correct
valueOf() is static method defined in String class. Hence the above code compiles and runs successfully and prints 98765 as an output.
Incorrect
valueOf() is static method defined in String class. Hence the above code compiles and runs successfully and prints 98765 as an output.
-
Question 12 of 19
12. Question
Which one of the expressions will evaluate to true if preceded by the following code?
String a = “hello”;
String b = new String(a);
String c = a;
char[] d = { ‘h’, ‘e’, ‘l’, ‘l’, ‘o’ };Correct
a.equals(b) returns true as equals() method compares content of two string if same or not.
Incorrect
a.equals(b) returns true as equals() method compares content of two string if same or not.
-
Question 13 of 19
13. Question
What will be the result of attempting to compile and run the following program?
- publicย classย MyClassย {
- ย ย ย ย publicย staticย voidย main(String[]ย args)ย {
- ย ย ย ย ย ย ย ย StringBufferย sbย =ย newย StringBuffer(“haveย aย niceย day“);
- ย ย ย ย ย ย ย ย sb.setLength(6);
- ย ย ย ย ย ย ย ย System.out.println(sb);
- ย ย ย ย }
- }
Correct
The program will print “have a” when run.
Incorrect
The program will print “have a” when run.
-
Question 14 of 19
14. Question
What will be written to the standard output when the following program is run?
- importย staticย java.lang.System.out;
- publicย classย TestOutputย {
- ย ย ย ย publicย staticย voidย main(String[]ย args)ย {
- ย ย ย ย ย ย ย ย Stringย spaceย =ย ”ย “;
- ย ย ย ย ย ย ย ย Stringย compositeย =ย spaceย +ย “windows”ย +ย spaceย +ย space;
- ย ย ย ย ย ย ย ย composite.concat(“server”);
- ย ย ย ย ย ย ย ย Stringย trimmedย =ย composite.trim();
- ย ย ย ย ย ย ย ย out.println(trimmed.length());
- ย ย ย ย }
- }
Correct
concat() method returns a String with the value of the String passed into the methodand append it to the end of the String used to invoke this method. Hence the value of composite does not change.
Incorrect
concat() method returns a String with the value of the String passed into the methodand append it to the end of the String used to invoke this method. Hence the value of composite does not change.
-
Question 15 of 19
15. Question
What is the output for following code snippet?
- Stringย stringย =ย “null”+null+“null”;
- System.out.println(string);
Correct
In java String class if String reference is null, it is converted to the string “null”.
Hence the above code returns nullnullnull as an output.
Incorrect
In java String class if String reference is null, it is converted to the string “null”.
Hence the above code returns nullnullnull as an output.
-
Question 16 of 19
16. Question
Given code snippet :-
String str1 = "Modern Pathshala"; String str2 = new String("Modern Pathshala"); String str3 = "Modern Pathshala";
How many objects are created?
Correct
In the above code snippet str1 is created in String Pool whereas String created using new operator i.e str2 is created in Heap. Further str3 refers to String Pool object which is already created.
Hence total 2 objects are created.
The pictorial representation of above object creation can be dsescribed as :-
Incorrect
In the above code snippet str1 is created in String Pool whereas String created using new operator i.e str2 is created in Heap. Further str3 refers to String Pool object which is already created.
Hence total 2 objects are created.
The pictorial representation of above object creation can be dsescribed as :-
-
Question 17 of 19
17. Question
What is the output of below code snippet?
System.out.println((“a” + “b” + “c”).intern() == “abc”); Correct
The Java programming language requires that identical string literals (that is, literals that contain the same sequence of characters) must refer to the same instance of class String. In addition, if the method String.intern is called on any string, the result is a reference to the same class instance that would be returned if that string appeared as a literal. Thus,
(“a” + “b” + “c”).intern() == “abc” must have the value true.
To derive a string literal, the Java virtual machine examines the sequence of characters given by the CONSTANT_String_info structure.
- If the method String.intern has previously been called on an instance of class String containing a sequence of Unicode characters identical to that given by the CONSTANT_String_info structure, then the result of string literal derivation is a reference to that same instance of class String.
- Otherwise, a new instance of class String is created containing the sequence of Unicode characters given by the CONSTANT_String_info structure; that class instance is the result of string literal derivation. Finally, the intern method of the new String instance is invoked.
Incorrect
The Java programming language requires that identical string literals (that is, literals that contain the same sequence of characters) must refer to the same instance of class String. In addition, if the method String.intern is called on any string, the result is a reference to the same class instance that would be returned if that string appeared as a literal. Thus,
(“a” + “b” + “c”).intern() == “abc” must have the value true.
To derive a string literal, the Java virtual machine examines the sequence of characters given by the CONSTANT_String_info structure.
- If the method String.intern has previously been called on an instance of class String containing a sequence of Unicode characters identical to that given by the CONSTANT_String_info structure, then the result of string literal derivation is a reference to that same instance of class String.
- Otherwise, a new instance of class String is created containing the sequence of Unicode characters given by the CONSTANT_String_info structure; that class instance is the result of string literal derivation. Finally, the intern method of the new String instance is invoked.
-
Question 18 of 19
18. Question
Given code snippet :-
String s;
int a;
s = “Foolish boy.”;
a = s.indexOf(“fool”);What is the output?
Correct
Incorrect
-
Question 19 of 19
19. Question
Identify error in below source code –
- publicย classย JavaStringIsEmpty
- {
- ย ย ย ย publicย staticย voidย main(Stringย args[])
- ย ย ย ย {
- ย ย ย ย ย ย ย ย Stringย strlย =ย “”;
- ย ย ย ย ย ย ย ย Stringย str2ย =ย null;
- ย ย ย ย ย ย ย ย Stringย str2ย =ย “Helloย Java”;
- ย ย ย ย ย ย ย ย System.out.println(“Isย Stringย 1ย empty?ย :”ย +ย strl.isEmpty());
- ย ย ย ย ย ย ย ย System.out.println(“Isย Stringย 3ย empty?ย :”ย +ย str3.isEmpty());
- ย ย ย ย }
- }
Correct
Same variable str2 is declared twice which is not allowed.
Incorrect
Same variable str2 is declared twice which is not allowed.