curriculum/challenges/english/blocks/quiz-classes-and-objects/67f413038f0f8c452c660dc5.md
To pass the quiz, you must correctly answer at least 9 of the 10 questions below.
Which of the following is the correct way to define a class?
def className(class):
pass
self className:
pass
class className
pass
class className:
pass
What is the purpose of the special method __init__?
It sets a shortcut to create an instance of a class.
It prevents an object from having duplicate attributes.
It sets the value of self to the current object.
It initializes objects' attributes upon instantiation.
What is the difference between an instance attribute and a class attribute?
Instance attributes define methods that can be accessed from an object; class attributes define methods that can be accessed from a class.
Instance attributes are set within the __init__ method; class attributes are set within the __class__ method.
Instance attributes can be directly accessed from the class; class attributes can be only accessed from an actual instance of the class.
Instance attributes belong to a specific object; class attributes belong to a class.
Which of the following is the correct way to call the spam method from the menu object?
spam.menu()
menu[spam]
spam.menu
menu.spam()
Which of the following special methods is called under the hood when an object is printed to the console?
__print__
__log__
__string__
__str__
What is the result of the following code?
class Menu:
dish_of_the_day = "spam"
print(Menu.dish_of_the_day)
None
AttributeError
SyntaxError
spam
What does the self parameter refer to inside a method?
It's a reference to the object initializer.
It's a reference to the module where the class is defined.
It's a reference to the class being used.
It's a reference to the instance of the class calling the method.
Which of the following correctly creates an instance of a class Person?
Person.new()
new Person()
new Person
Person()
What will be the result of the following code?
class Dog:
def __init__(name, age):
self.name = name
self.age = age
dog = Dog("Pinky", 3)
print(dog.name)
Pinky
3
AttributeError
TypeError
Which of the following is the correct way to access the name attribute of the dog object?
dog().name
dog.name()
dog.get('name')
dog.name