Ruby Variables MCQ
11. Instance variables in ruby begin with?
A. @
B. #
C. $
D. &
View Answer
Ans : A
Explanation: Instance variables begin with @.
12. Class variables in ruby begin with?
A. @
B. #
C. double @
D. ##
View Answer
Ans : C
Explanation: Class variables begin with @@
13. Default value of class variables is?
A. nil
B. infinite
C. -1
D. error
View Answer
Ans : D
Explanation: uninitialized class variable produces an error.
14. Constants in ruby begin with ?
A. Lowercase
B. !
C. !
D. Uppercase
View Answer
Ans : D
Explanation: Constants begin with an uppercase letter.
15. Which of the following Ruby Pseudo Variables is used to return the name of the current source file?
A. _FILE_
B. _CURRENT_
C. _LINE_
D. None of the above
View Answer
Ans : A
Explanation: __FILE__ : The name of the current source file.
16. Why
notation is used in Ruby?
A. Formfeed
B. Escape
C. Carriage return
D. Bell
View Answer
Ans : C
Explanation:
: Carriage return (0x0d)
17. Why can not we use quotation marks ("or") with boolean?
A. It indicates that we are talking about a string
B. It indicates that we are assining a value
C. It indicates that that we are replacing boolean data type with string data type
D. None of the above
View Answer
Ans : A
Explanation: Quotation marks are used only with strings.
18. What is the output of the given code?
my_string=Ruby
puts(my_string)
A. Ruby
B. Nil
C. Error
D. my_string
View Answer
Ans : C
Explanation: Ruby should be written in double quotes inorder to indicate a string.
19. Which type of number(0b1011 ) is ?
A. Octal
B. Hexadecimal
C. Binary
D. Decimal
View Answer
Ans : C
Explanation: Binary number is the answer.
20. Objects of which class does the integer from the range -2^30 to 2^(30-1) belong to?
A. Octal
B. Bignum
C. Fixnum
D. Binary
View Answer
Ans : C
Explanation: Integer within this range are objects of the class fixnum.
Discussion