1/11
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
A class definition introduces a new data type, or type of object, in your program.
a. True
b. False
a. True
A class defines groupings of related variables called attributes. Each object, or instance, of a class has those attributes.
a. True
b. False
a. True
A method of a class is a special kind of function that all objects (instances) of the class will have available for calling.
a. True
b. False
a. True
Imagine a class named Pasta where the following lines of code are valid:
p0: Pasta = Pasta()
p0.sauce = "marinara" p0.noodle = "spaghetti"
p1: Pasta = Pasta()
p1.sauce = "fettuccine" p1.noodle = "farfalle" print(p1.price())
In the method call to Pasta#price, self would contain a reference to the same Pasta object as which variable above?
a. p0
b. p1
c. No way to know.
b. p1
The first parameter of a method is self and it is given a reference to the object the method was called on.
a. True
b. False
a. True
The constructor of a class is only called once in a program, no matter how many objects of that class are constructed.
a. True
b. False
b. False
The constructor of a class is responsible for initializing the attributes of a new object (instance) before that object is used.
a. True
b. False
a. True
Assume a class named Point. The following code listing results in a method call and not a constructor call.
a: Point = Point(3, 4)
a. True
b. False
b. False
Assume a class named Point. The following code listing results in a constructor call and a method call.
a: Point = Point(1, -1) a.invert()
a. True
b. False
a. True
The name of a constructor in a Python class definition is __init__.
a. True
b. False
a. True
The first parameter of a constructor is self and it is given a reference to the newly constructed object on the heap.
a. True
b. False
a. True
You should assume there is an automatic statement at the end of each constructor which is:
return self
a. True
b. False
a. True