Ruby String MCQ
This section focuses on "String" MCQs in Ruby. These Multiple Choice Questions (MCQ) should be practiced to improve the Ruby skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. StringĀ is a sequence of _________ characters.
A. one
B. many
C. Both A and B
D. None of the above
View Answer
Ans : C
Explanation: stringĀ is a sequence of one or more characters
2. String may consists of?
A. Number
B. letter
C. Special character
D. All of the above
View Answer
Ans : D
Explanation: String may consist of numbers, letters, or symbols.
3. String are?
A. mutable
B. unmutable
C. Both A and B
D. None of the above
View Answer
Ans : A
Explanation: strings are mutable, i.e. strings can be changed in place instead of creating new strings.
4. Double quotes and single quotes will interpolates ?
A. TRUE
B. FALSE
C. double quotes will interpolates
D. Single quotes will interpolates
View Answer
Ans : C
Explanation: In string, double quotes will interpolates while single quotes will not interpolates.
5. What will be output for the folowing code?
str1 = "LFC" puts 'str1: #{str1}'
A. str1: LFC
B. str1: #{str1}
C. str1: {LFC}
D. str1: #{LFC}
View Answer
Ans : B
Explanation: Cannot Interpolate so output is str1: #{str1}.
6. what will be output for the following code?
str1 = LFC puts "str1: #{str1}"
A. str1: LFC
B. str1: #{str1}
C. str1: {LFC}
D. str1: #{LFC}
View Answer
Ans : A
Explanation: Interpolating str2: LFC.
7. What will be output for the following code?
str2 = String.new ""LetsFindCourse""
puts str2
A. LETSFINDCOURSE
B. letsfindcourse
C. Error
D. LetsFindCourse
View Answer
Ans : D
Explanation: using new method to create string object and assigning value to it.
8. In ruby, User can access the string elements by using the__________?
A. {}
B. []
C. ()
D. All of the above
View Answer
Ans : B
Explanation: User can access the string elements by using the square brackets []. In square brackets [], the user can pass the strings, ranges or indexes.
9. What will be output for the following code?
str = "LetsFindCourse Ruby MCQs" puts str[2]
A. t
B. e
C. MCQs
D. Ruby
View Answer
Ans : A
Explanation: passing index as an argument which returns the specified character , so t is the output.
10. What will be output for the following code?
str = "LetsFindCourse Ruby MCQs" puts str[-2]
A. Q
B. t
C. C
D. Error
View Answer
Ans : A
Explanation: passing the negative index as an argument which returns the specified character from the last of the string.
Discussion