Objective programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q
class Car
  def initialize(make, model)
    \_\_\_make = make
    \_\_\_model = model
  end
end

kitt = Car.new(“Pontiac”, “Trans Am”)

A

@

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
class Car
  def initialize(\_\_\_, \_\_\_\_)
    @make = make
    @model = model
  end
end

kitt = Car.new(“Pontiac”, “Trans Am”)

A

make, model

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
class Car
  \_\_\_ initialize(make, model)
    @make = make
    @model = model
  end
end

kitt = Car.new(“Pontiac”, “Trans Am”)

A

def

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
class Car
  def initialize(make, model)
    @make = make
    @model = model
  end
end

kitt = Car.___(“Pontiac”, “Trans Am”)

A

new

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

to make a global variable in methods

class MyClass
  \_\_\_\_my_variable = "Hello!"
end

puts ____my_variable

A

$

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

@@

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
class Car
  def \_\_\_\_\_(make, model)
   @make = make
   @model = model
  end
end

kitt = Car.new(“Pontiac”, “Trans Am”)

A

initialize

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly