Object Oriented Programming II
1.
What is the purpose of the 'include?' method in Ruby?
To include a class in a module
To check if a value exists in an array
To include a module in a class
To check if an object is an instance of a specific class
2.
Which method is used to convert a string to uppercase in Ruby?
toupper
upcase
uppercase
to_uppercase
3.
In Ruby, how can you define a class constant?
Using the 'constantize' method
Using the 'constant' keyword
Using the 'const' keyword
Using the 'const_set' method
4.
Which method is used to remove the last element from an array in Ruby?
delete
remove
pop
truncate
5.
In Ruby, what does the 'attr_writer' declaration do?
Defines a readable attribute
Defines a writable attribute
Defines both readable and writable attributes
Defines a constant
6.
What does the term 'duck typing' mean in Ruby?
Checking the type of an object at runtime
Defining types explicitly in code
Dynamic typing with runtime type checking
Static typing with compile-time type checking
7.
What is the purpose of the 'protected' keyword in Ruby?
To make a method accessible only within its defining class and its subclasses
To make a method accessible globally
To make a method accessible only within its defining class
To make a method accessible only within the same module
8.
What is the role of the 'super' keyword in the context of method overriding in Ruby?
It overrides the superclass's method
It calls the superclass's method
It defines a new method in the subclass
It prevents method overriding
9.
How does Ruby support multiple inheritance?
By using the 'multiple' keyword
Using the 'extends' keyword
By allowing a class to inherit from multiple classes
Using the 'include' keyword
10.
What is the purpose of the 'protected' visibility in Ruby?
To make a method accessible only within the same module
To make a method accessible globally
To make a method accessible only within its defining class and its subclasses
To make a method accessible only within the defining class
11.
How are instance variables in Ruby different from class variables?
Instance variables belong to a specific instance of a class
Class variables are shared among all instances of a class
Instance variables are shared among all instances of a class
Class variables belong to a specific instance of a class
12.
What does the acronym 'MVC' stand for in the context of software architecture?
Model View Control
Model View Command
Model View Code
Model View Controller
13.
What is the purpose of the 'yield' keyword in Ruby blocks?
To return a value from a block
To pass control back to the calling method
To terminate a block of code
To define a block of code
14.
What is the purpose of the 'load' method in Ruby?
To load external libraries
To load and execute Ruby files
To load class definitions
To load module definitions
15.
Which keyword is used to define a module in Ruby?
class
module
mod
namespace
16.
What is the significance of the 'self' keyword in Ruby class methods?
Refers to the current instance of the class
Refers to the superclass
Refers to the current class
Refers to the parent class
17.
What is the purpose of the 'freeze' method in Ruby?
To defrost an object
To freeze an object and prevent further modifications
To duplicate an object
To thaw an object
18.
What is the role of the 'private' keyword in Ruby?
To make a method accessible only within the same module
To make a method accessible globally
To make a method accessible only within the defining class
To make a method accessible only within the defining class and its subclasses
19.
In Ruby, what is the purpose of the 'super' keyword in the constructor?
It calls the superclass's constructor
It overrides the superclass's constructor
It defines a new constructor in the subclass
It prevents constructor overriding
20.
What is method chaining in Ruby?
Defining methods with the same name in different classes
Calling multiple methods on the same object in a single line
Calling the same method multiple times
Creating a chain of methods with the same name