Classes And Objects In Ruby MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Classes And Objects In Ruby with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
31
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
38 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
31
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/31 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 31 questions answered.
Question 1 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the keyword used to define a class in Ruby?
Correct Answer: Option A — class
Detailed Academic Explanation:
class is the correct answer to “What is the keyword used to define a class in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 2 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to create a new instance of a class in Ruby?
Correct Answer: Option A — new
Detailed Academic Explanation:
new is the correct answer to “Which keyword is used to create a new instance of a class in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 3 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you define a constructor in Ruby?
Correct Answer: Option A — def initialize
Detailed Academic Explanation:
def initialize is the correct answer to “How do you define a constructor in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 4 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is used to access instance variables in Ruby?
Correct Answer: Option A — @variable
Detailed Academic Explanation:
@variable is the correct answer to “Which of the following is used to access instance variables in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 5 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the attr_accessor method do in Ruby?
Correct Answer: Option A — Creates getter and setter methods for an instance variable
Detailed Academic Explanation:
Creates getter and setter methods for an instance variable is the correct answer to “What does the attr_accessor method do in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 6 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the initialize method in Ruby?
Correct Answer: Option D — To initialize object properties
Detailed Academic Explanation:
To initialize object properties is the correct answer to “What is the purpose of the initialize method in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 7 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the method used to inherit from a superclass in Ruby?
Correct Answer: Option A — <
Detailed Academic Explanation:
< is the correct answer to “What is the method used to inherit from a superclass in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 8 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the super keyword do in Ruby?
Correct Answer: Option A — Calls the method of the superclass with the same name
Detailed Academic Explanation:
Calls the method of the superclass with the same name is the correct answer to “What does the super keyword do in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 9 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the method used to check if an object is an instance of a particular class in Ruby?
Correct Answer: Option C — is_a?
Detailed Academic Explanation:
is_a? is the correct answer to “What is the method used to check if an object is an instance of a particular class in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 10 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the method used to define class methods in Ruby?
Correct Answer: Option A — def self.method_name
Detailed Academic Explanation:
def self.method_name is the correct answer to “What is the method used to define class methods in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 11 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the method used to define instance methods in Ruby?
Correct Answer: Option A — def method_name
Detailed Academic Explanation:
def method_name is the correct answer to “What is the method used to define instance methods in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 12 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the keyword used to refer to the current instance of a class in Ruby?
Correct Answer: Option A — self
Detailed Academic Explanation:
self is the correct answer to “What is the keyword used to refer to the current instance of a class in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 13 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to define class variables in Ruby?
Correct Answer: Option A — @@variable
Detailed Academic Explanation:
@@variable is the correct answer to “Which method is used to define class variables in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 14 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the private keyword do in a Ruby class?
Correct Answer: Option A — It makes methods private, accessible only within the class
Detailed Academic Explanation:
It makes methods private, accessible only within the class is the correct answer to “What does the private keyword do in a Ruby class”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 15 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the protected keyword do in a Ruby class?
Correct Answer: Option A — It makes methods protected, accessible only within the class and its subclasses
Detailed Academic Explanation:
It makes methods protected, accessible only within the class and its subclasses is the correct answer to “What does the protected keyword do in a Ruby class”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 16 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you access instance variables in Ruby?
Correct Answer: Option B — Using instance methods
Detailed Academic Explanation:
Using instance methods is the correct answer to “How do you access instance variables in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 17 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the method used to define instance variables in Ruby?
Correct Answer: Option A — @variable_name
Detailed Academic Explanation:
@variable_name is the correct answer to “What is the method used to define instance variables in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 18 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to inherit a class in Ruby?
Correct Answer: Option D — <
Detailed Academic Explanation:
< is the correct answer to “Which keyword is used to inherit a class in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 19 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the super keyword do in Ruby classes?
Correct Answer: Option A — Calls the method of the superclass with the same name
Detailed Academic Explanation:
Calls the method of the superclass with the same name is the correct answer to “What does the super keyword do in Ruby classes”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 20 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the syntax for defining a class method in Ruby?
Correct Answer: Option A — def self.method_name
Detailed Academic Explanation:
def self.method_name is the correct answer to “What is the syntax for defining a class method in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 21 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the method used to define a class variable in Ruby?
Correct Answer: Option A — @@variable_name
Detailed Academic Explanation:
@@variable_name is the correct answer to “What is the method used to define a class variable in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 22 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the method used to access class variables in Ruby?
Correct Answer: Option C — Using class methods
Detailed Academic Explanation:
Using class methods is the correct answer to “What is the method used to access class variables in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 23 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the syntax for defining an instance method in Ruby?
Correct Answer: Option A — def method_name
Detailed Academic Explanation:
def method_name is the correct answer to “What is the syntax for defining an instance method in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 24 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to define getter and setter methods for instance variables in Ruby?
Correct Answer: Option A — attr_accessor
Detailed Academic Explanation:
attr_accessor is the correct answer to “Which method is used to define getter and setter methods for instance variables in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 25 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to call a method on an object in Ruby?
Correct Answer: Option D — none of the above
Detailed Academic Explanation:
none of the above is the correct answer to “Which keyword is used to call a method on an object in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 26 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the syntax for defining a class in Ruby?
Correct Answer: Option B — class
Detailed Academic Explanation:
class is the correct answer to “What is the syntax for defining a class in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 27 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you access class variables in Ruby?
Correct Answer: Option C — Using class methods
Detailed Academic Explanation:
Using class methods is the correct answer to “How do you access class variables in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 28 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the method used to define a class method in Ruby?
Correct Answer: Option A — def self.method_name
Detailed Academic Explanation:
def self.method_name is the correct answer to “What is the method used to define a class method in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 29 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the method used to create a new instance of a class in Ruby?
Correct Answer: Option A — new
Detailed Academic Explanation:
new is the correct answer to “What is the method used to create a new instance of a class in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 30 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the method used to access instance variables in Ruby?
Correct Answer: Option B — Using instance methods
Detailed Academic Explanation:
Using instance methods is the correct answer to “What is the method used to access instance variables in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
Question 31 of 31
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to define a class method in Ruby?
Correct Answer: Option A — def self.method_name
Detailed Academic Explanation:
def self.method_name is the correct answer to “Which method is used to define a class method in Ruby”. This question is standard in competitive examination syllabi for Classes And Objects In Ruby.
💡Key Conceptual Anchor:Classes And Objects In Ruby
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.