#1
Which of the following is the correct way to declare a string variable in Java?
String myString;
ExplanationDeclares a string variable named 'myString' in Java.
#2
What does the 'new' keyword do when initializing a string variable in Java?
Creates a new instance of the String class
ExplanationCreates a new instance of the String class in Java.
#3
Which of the following is a correct way to concatenate strings in Python?
string1 + string2
ExplanationConcatenates two strings in Python.
#4
In JavaScript, which method is used to find the length of a string?
length
ExplanationFinds the length of a string in JavaScript.
#5
Which of the following is NOT a valid way to declare a string variable in C++?
String myString;
ExplanationInvalid way to declare a string variable in C++.
#6
In Python, what will the expression 'len('hello')' return?
5
ExplanationReturns the length of the string 'hello', which is 5, in Python.
#7
Which of the following characters is used to represent the end of a string in C programming?
\0
ExplanationNull terminator '\0' is used to represent the end of a string in C.
#8
In C++, what is the result of the following code: string myString = "Hello" + "World";
Compilation error
ExplanationResults in a compilation error in C++ due to invalid string concatenation syntax.
#9
Which method is used to compare two string objects in Java?
equals()
ExplanationCompares two string objects in Java.
#10
What is the output of the following C# code: string str = "hello"; Console.WriteLine(str[0]);
h
ExplanationPrints the first character 'h' of the string 'hello' in C#.
#11
Which of the following methods is used to convert a string to uppercase in Python?
upper()
ExplanationConverts a string to uppercase in Python.
#12
Which of the following methods is used to check if a string contains a specific substring in JavaScript?
includes()
ExplanationChecks if a string contains a specific substring in JavaScript.
#13
What is the output of the following C# code: string str = "hello"; Console.WriteLine(str.ToUpper());
HELLO
ExplanationPrints the string 'hello' converted to uppercase in C#.
#14
Which operator is used for string concatenation in PHP?
.
ExplanationDot operator '.' is used for string concatenation in PHP.
#15
What is the difference between String and StringBuilder in Java?
String is immutable whereas StringBuilder is mutable
ExplanationString is immutable, meaning its value cannot be changed after creation, whereas StringBuilder is mutable.
#16
In Java, what is the purpose of the 'intern()' method in the String class?
To store a common string pool
ExplanationStores strings in a common pool to optimize memory usage in Java.
#17
In Java, which method is used to convert an int to a string?
String.valueOf()
ExplanationConverts an int to a string in Java.
#18
In C++, what function is used to find the length of a string?
strlen()
ExplanationFinds the length of a string in C++ using the strlen() function.
#19
Which method is used to find the last index of a substring within a string in Java?
lastIndexOf()
ExplanationFinds the last occurrence of a substring within a string in Java.