Objective programming Flashcards
1
Q
class Car def initialize(make, model) \_\_\_make = make \_\_\_model = model end end
kitt = Car.new(“Pontiac”, “Trans Am”)
A
@
2
Q
class Car def initialize(\_\_\_, \_\_\_\_) @make = make @model = model end end
kitt = Car.new(“Pontiac”, “Trans Am”)
A
make, model
3
Q
class Car \_\_\_ initialize(make, model) @make = make @model = model end end
kitt = Car.new(“Pontiac”, “Trans Am”)
A
def
4
Q
class Car def initialize(make, model) @make = make @model = model end end
kitt = Car.___(“Pontiac”, “Trans Am”)
A
new
5
Q
to make a global variable in methods
class MyClass \_\_\_\_my_variable = "Hello!" end
puts ____my_variable
A
$
6
Q
class Person # Set your class variable to 0 on line 3 \_\_\_\_people_count = 0
def initialize(name) @name = name # Increment your class variable on line 8 @@people_count += 1 end
def self.number_of_instances # Return your class variable on line 13 return @@people_count end end
A
@@
7
Q
class Person # Set your class variable to 0 on line 3 @@people_count = 0
def initialize(name) @name = name # Increment your class variable on line 8 \_\_\_\_\_\_ end
def self.number_of_instances # Return your class variable on line 13 return @@people_count end end
A
@@people_count += 1
8
Q
class Car def \_\_\_\_\_(make, model) @make = make @model = model end end
kitt = Car.new(“Pontiac”, “Trans Am”)
A
initialize
9
Q
class Person # Set your class variable to 0 on line 3 @@people_count = 0
def initialize(name) @name = name # Increment your class variable on line 8 @@people_count += 1 end
def \_\_\_\_\_.number_of_instances # Return your class variable on line 13 return @@people_count end end
A
self
10
Q
class Person @@people_count = 0
def initialize(name)
@name = name
@@people_count += 1
end
def self.number_of_instances
return @@people_count
end
end
matz = Person.new("Yukihiro") dhh = Person.new("David")
puts “Number of Person instances: #_____”
A
{Person.number_of_instances}
11
Q
class Message @@messages_sent = 0 def initialize(from, to) @from = from @to = to @@messages_sent += 1 end end
class Email ____ Message
def initialize(from, to)
___
end
end
my_message = Message.new(“me”, “you”)
A
super