
java
Authored by teja vadlamudi
Information Technology (IT)
University

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How to create a new String object in Java?
Answer explanation
Explanation:
The new String(); syntax is used to create a new String object in Java.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
2. What is the output of “Java” == “Java” in Java?
a) true
b) false
c) Compilation error
d) Runtime error
Answer explanation
Explanation:
Both string literals point to the same object in the string pool, so == will return true.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
3. What does the charAt() method do?
a) Returns the character at a specific index
b) Changes the character at a specific index
c) Removes the character at a specific index
d) None of the above
Answer explanation
Explanation:
The charAt(int index) method returns the character at the specified index in the string.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the result of statement: String str = null;?
a) Creates a new String with no characters
b) Creates a String pointing to “null”
c) Does not create any String
d) Creates an empty String
Answer explanation
Explanation:
Declaring a String variable as null means it does not point to any memory location for an object.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
5.Which method removes whitespace from the beginning and end of a string?
a) trim()
b) strip()
c) clean()
d) chop()
Answer explanation
Explanation:
The trim() method removes whitespace from both the beginning and the end of the string.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
6.Is the String class in Java thread-safe?
a) Yes
b) No
c) Only when synchronized
d) Depends on the method being called
Answer explanation
Explanation:
Strings in Java are immutable, which means once a String object is created, its value cannot be modified. This inherent immutability makes them thread-safe, as multiple threads cannot change their value simultaneously.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
7.What is the String Constant Pool in Java?
a) A pool where all string methods are stored
b) A special area of the heap memory where string literals are stored and reused
c) A memory space where string objects are stored temporarily
d) A section of the Java library dedicated to string operations
Answer explanation
The String Constant Pool is a specific area in the heap memory where Java stores string literals. The primary purpose of this is to save memory by reusing existing strings.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?