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.

What is the method used to define instance methods in Ruby?

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

What is the method used to define class methods 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

What is the method used to check if an object is an instance of a particular class in Ruby?

  1. A. instance_of?
  2. B. is_instance?
  3. C. is_a?
  4. D. object_of?
Report Error

What does the super keyword do in Ruby?

  1. A. Calls the method of the superclass with the same name
  2. B. Calls the method of the subclass with the same name
  3. C. Exits the method
  4. D. Returns a value
Report Error

What is the method used to inherit from a superclass in Ruby?

  1. A. <
  2. B. -<
  3. C. extends
  4. D. inherit
Report Error

What is the purpose of the initialize method in Ruby?

  1. A. To initialize class variables
  2. B. To define instance methods
  3. C. To create object instances
  4. D. To initialize object properties
Report Error

What does the attr_accessor method do in Ruby?

  1. A. Creates getter and setter methods for an instance variable
  2. B. Creates only getter methods for an instance variable
  3. C. Creates only setter methods for an instance variable
  4. D. Creates private methods for an instance variable
Report Error

Which of the following is used to access instance variables in Ruby?

  1. A. @variable
  2. B. $variable
  3. C. @@variable
  4. D. variable
Report Error

How do you define a constructor in Ruby?

  1. A. def initialize
  2. B. def constructor
  3. C. def init
  4. D. def constructor()
Report Error

Which keyword is used to create a new instance of a class in Ruby?

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

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

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