Commerce

Classes And Objects In Ruby MCQs

Practice Classes And Objects In Ruby MCQs for competitive exams.

Classes And Objects In Ruby MCQs

Practice questions from this topic.

Which method is used to define a class method in Ruby?

  1. A. def self.method_name
  2. B. def class.method_name
  3. C. def method_name.self
  4. D. def method_name.static
Report Error

Which keyword is used to define a class in Ruby?

  1. A. class MyClass
  2. B. class
  3. C. def class
  4. D. define class
Report Error

What is the method used to access instance variables in Ruby?

  1. A. Using accessor methods
  2. B. Using instance methods
  3. C. Using class methods
  4. D. Using global variables
Report Error

What is the method used to create a new instance of a class in Ruby?

  1. A. new
  2. B. create
  3. C. initialize
  4. D. instance
Report Error

What is the method used to define a class method in Ruby?

  1. A. def self.method_name
  2. B. def class.method_name
  3. C. def method_name.self
  4. D. def method_name.static
Report Error

How do you access class variables in Ruby?

  1. A. Using accessor methods
  2. B. Using instance methods
  3. C. Using class methods
  4. D. Using global variables
Report Error

What is the syntax for defining a class in Ruby?

  1. A. class MyClass
  2. B. class
  3. C. def class
  4. D. define class
Report Error

Which keyword is used to call a method on an object in Ruby?

  1. A. call
  2. B. invoke
  3. C. execute
  4. D. none of the above
Report Error

What is the purpose of the attr_reader method in Ruby classes?

  1. A. To create only getter methods for instance variables
  2. B. To create only setter methods for instance variables
  3. C. To create both getter and setter methods for instance variables
  4. D. To create instance methods
Report Error

Which method is used to define getter and setter methods for instance variables in Ruby?

  1. A. attr_accessor
  2. B. get_set
  3. C. setter_getter
  4. D. set_get
Report Error

What is the syntax for defining an instance method in Ruby?

  1. A. def method_name
  2. B. def self.method_name
  3. C. def method_name.self
  4. D. def method_name.static
Report Error

What is the purpose of the attr_accessor method in Ruby classes?

  1. A. To create getter and setter methods for instance variables
  2. B. To define class methods
  3. C. To define instance methods
  4. D. To create new instances
Report Error