Java Programming Multiple Choice Questions - String
This section focuses on the "String" in Java programming. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements and other competitive examinations.
1. _________ are a sequence of characters.
A. Character
B. Strings
C. Integer
D. Classes
View Answer
Ans : B
Explanation: Strings, which are widely used in Java programming, are a sequence of characters.
2. In Java programming language, strings are treated as objects.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: True, In Java programming language, strings are treated as objects.
3. The String class is?
A. mutable
B. immutable
C. Both A and B
D. None of the above
View Answer
Ans : B
Explanation: The String class is immutable, so that once it is created a String object cannot be changed.
4. Methods used to obtain information about an object are known as?
A. string methods
B. class methods
C. object method
D. accessor methods
View Answer
Ans : D
Explanation: Methods used to obtain information about an object are known as accessor methods. One accessor method that you can use with strings is the length() method, which returns the number of characters contained in the string object.
5. Which methods to print output with formatted numbers?
A. printf()
B. format()
C. formatted()
D. Both A and B
View Answer
Ans : D
Explanation: You have printf() and format() methods to print output with formatted numbers. The String class has an equivalent class method, format(), that returns a String object rather than a PrintStream object.
6. Which method returns the character at the specified index?
A. int compareTo(Object o)
B. int compareTo(String anotherString)
C. char charAt(int index)
D. int compareToIgnoreCase(String str)
View Answer
Ans : C
Explanation: char charAt(int index) : Returns the character at the specified index.
7. Which method returns a String that represents the character sequence in the array specified?
A. int compareToIgnoreCase(String str)
B. String concat(String str)
C. boolean contentEquals(StringBuffer sb)
D. static String copyValueOf(char[] data)
View Answer
Ans : C
Explanation: boolean contentEquals(StringBuffer sb) : Returns true if and only if this String represents the same sequence of characters as the specified StringBuffer.
8. Which of the following is true about boolean equals(Object anObject)?
A. Tests if this string ends with the specified suffix
B. Compares this string to the specified object
C. Compares this String to another String, ignoring case considerations
D. None of the above
View Answer
Ans : B
Explanation: boolean equals(Object anObject) : Compares this string to the specified object.
9. Which of these method of String class is used to obtain character at specified index?
A. char()
B. Charat()
C. charat()
D. charAt()
View Answer
Ans : D
Explanation: charAt() method of String class is used to obtain character at specified index.
10. Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super.
A. Yes
B. No
C. Can be yes or no
D. Can not say
View Answer
Ans : A
Explanation: Yes, Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super.
Discussion