Learn Mode

String Variable Declarations and Initialization Quiz

#1

Which of the following is the correct way to declare a string variable in Java?

String myString;
Explanation

Declares 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
Explanation

Creates 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
Explanation

Concatenates two strings in Python.

#4

In JavaScript, which method is used to find the length of a string?

length
Explanation

Finds 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;
Explanation

Invalid way to declare a string variable in C++.

#6

In Python, what will the expression 'len('hello')' return?

5
Explanation

Returns 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
Explanation

Null 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
Explanation

Results 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()
Explanation

Compares two string objects in Java.

#10

What is the output of the following C# code: string str = "hello"; Console.WriteLine(str[0]);

h
Explanation

Prints 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()
Explanation

Converts 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()
Explanation

Checks 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
Explanation

Prints the string 'hello' converted to uppercase in C#.

#14

Which operator is used for string concatenation in PHP?

.
Explanation

Dot 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
Explanation

String 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
Explanation

Stores 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()
Explanation

Converts an int to a string in Java.

#18

In C++, what function is used to find the length of a string?

strlen()
Explanation

Finds 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()
Explanation

Finds the last occurrence of a substring within a string in Java.

Test Your Knowledge

Craft your ideal quiz experience by specifying the number of questions and the difficulty level you desire. Dive in and test your knowledge - we have the perfect quiz waiting for you!