Test Series - oops

Test Number 78/78

Q: Which is a true statement for object of String class?
A. Object are immutable
B. Object are mutable
C. Object are created only once
D. Object can’t be created
Solution: The object of string class are mostly immutable. This means that the String objects are constant. These can’t be changed once created.
Q: How to declare an object of class String?
A. String object_Name = value;
B. String object_name = new;
C. String object_name= new value;
D. String object_name= value new;
Solution: The class name String is given. And then the object name is mentioned. There are two ways to declare and initialize the string. Either by giving direct string value or by using new keyword. But if new operator is used, constructor of String class have to be called. From the given options, the direct string value declaration is correct.
Q: String class provides function toUpper() to __________________
A. Convert first character to uppercase
B. Convert last character to uppercase
C. Convert the whole string characters to uppercase
D. Convert uppercase to lower and lower to uppercases
Solution: The function is used to convert each character of the string. If the character is already uppercase then it remains the same. But if some character is in lowercase then it will be converted to uppercase.
Q: Function equals() is _______________ and equalIgnoreCase() is _________________
A. Case Insensitive, case insensitive
B. Case sensitive, Case insensitive
C. Case sensitive, case sensitive
D. Case insensitive, case sensitive
Solution: Both the functions return Boolean value. The function equal() is case sensitive and returns false even if a single character is case different in two strings. The other function ignores the case sensitivity and only checks if the spellings are same.
Q: String class have a concat() function that is used to _______
A. Replace old string by new string
B. Add two strings
C. Append one string at end of another string
D. Remove a string from end of one string
Solution: The concat function is used to append string into another string. The new string is always appended at the end of source string. The target string is appended as it is and the whole string is then ended by null character.
Q: The string class deals with string of only character type.
A. True
B. False
C. 1
D. 0
Solution: The string class objects can be used for any string consisting of characters. The characters include numbers, alphabets and few special characters. String class is not necessary to be used but provides a huge set of inbuilt functions to make the string operations easier.
Q: What does function length do in String class?
A. Returns length of string including null character
B. Returns length of string excluding null character
C. Returns length of substring
D. Returns size of string in bytes
Solution: The length function returns the length of string. The length is the number of characters in the string but the last null character is not counted. The string length can be used to loop through each character in the string.
Q: String trim() function is used to ________________
A. Remove all the white spaces from the string
B. Remove white space from start of string
C. Remove white space at end of string
D. Remove white space from both the ends of string
Solution: The function is used to remove any white space from both the ends of a given string. The white space include space, tab, next line etc. It will be removed both from the starting of string and from the end of string.
Q: Which is the function to get the character present at a particular index in the string?
A. char charAt(index);
B. char charIn(StringName);
C. char charAt(StringName);
D. char charIn(index);
Solution: The function can be called using dot operator with the string object. Char is the return type of the function to return the character at specified position. The index must be an integer value, less than the length of string.
Q: The compareTo() function is used to ____________
A. Compare strings value to string object
B. Compare string value to string value
C. Compare string object to another string object
D. Compare string object to another string value
Solution: The source and target must be objects of the string class. The compare is always case sensitive. To compare two string objects without case sensitivity then we can use compareToIgnoreCase() function.

You Have Score    /10