Object Oriented Programming I
1.
What does the term 'polymorphism' mean in object-oriented programming?
The ability of an object to have multiple names
The ability of an object to take many forms
The ability of an object to change its class
The ability of an object to have multiple methods
2.
What is a symbol in Ruby?
A string
An integer
A unique identifier
A reserved keyword
3.
Which method is used to create a new instance of a class in Ruby?
create
initialize
new
instantiate
4.
How can you create a private method in a Ruby class?
private_method
protected
private
secret
5.
In Ruby, what is the purpose of the 'attr_accessor' declaration?
To define only readable attributes
To define both readable and writable attributes
To define a constant
To define a private attribute
6.
Which method is called when an object is about to be destroyed in Ruby?
delete
destroy
finalize
deallocate
7.
In Ruby, what is the purpose of the 'include' keyword in a class?
To include a class's methods and constants
To inherit from another class
To include a module's methods and constants
To include a superclass's methods
8.
What is the purpose of the 'yield' keyword in Ruby?
To terminate a block of code
To pass control to the next iteration of a loop
To define a block of code
To transfer control to the calling method
9.
What is the difference between 'include' and 'extend' in Ruby module inclusion?
Include' adds module methods as class methods, 'extend' adds them as instance methods
Include' adds module methods as instance methods, 'extend' adds them as class methods
There is no difference between 'include' and 'extend'|'Include' and 'extend' both add module methods as class methods
Include' and 'extend' both add module methods as class methods
10.
What is the keyword used to define a class in Ruby?
def
class
type
struct
11.
Inheritance in Ruby is implemented using?
extends
inherits
<
< <
12.
What is the purpose of the 'initialize' method in a Ruby class?
To define class variables
To create an object
To initialize instance variables
To define methods
13.
Which keyword is used to call the superclass's method in Ruby?
superclass
parent
super
base
14.
What does the acronym 'DRY' stand for in the context of object-oriented programming?
Do Repeat Yourself
Don't Refactor Yourself
Don't Repeat Yourself
Do Refactor Yourself
15.
What is encapsulation in object-oriented programming?
Combining data and methods into a single unit
Exposing implementation details and hiding the interface
Hiding implementation details and exposing the interface
Separating data and methods into different units
16.
What is the purpose of the 'attr_reader' in Ruby?
To define a writable attribute
To define a readable attribute
To define both readable and writable attributes
To define a constant
17.
Which operator is used for concatenating strings in Ruby?
&
^
<<
~
18.
What is the difference between 'puts' and 'print' in Ruby?
puts adds a new line after printing
print adds a new line after printing
puts doesn't add a new line after printing
print adds extra spaces
19.
What is the purpose of the 'self' keyword in Ruby?
To refer to the current class
To refer to the superclass
To refer to the current instance of the class
To refer to the parent class
20.
What is the difference between 'shallow copy' and 'deep copy' in Ruby?
Shallow copy duplicates the outermost object, deep copy duplicates the entire object hierarchy
Deep copy duplicates the outermost object, shallow copy duplicates the entire object hierarchy
There is no difference between shallow copy and deep copy
Shallow copy and deep copy both duplicate only the outermost object