Deck 10: Astronomy: Creating Classes, Writing Constructors, Accessors, Mutators and Special Methods

Full screen (f)
exit full mode
Question
Every Python object is an instance of a(n):

A) data model.
B) class.
C) method.
D) algorithm.
Use Space or
up arrow
down arrow
to flip the card.
Question
The details about what an object can do are called:

A) methods.
B) instance data.
C) models.
D) data types.
Question
Which of the following is one of Python's collection classes?

A) int
B) float
C) bool
D) str
Question
The ____ operator is used to invoke a method of an object.

A) dot
B) equals
C) dash
D) star
Question
Case Study 1:
>>> count = 1
>>> count = count + 1
>>> count
2
>>> count = count.__add__(1)
>>> count
3
>>>
>>> mylist.__getitem__(1)
66
-Refer to the session in the accompanying Case Study 1. What is the equivalent of the + operator?

A) __getItem__
B) __add__
C) ++
D) =
Question
Case Study 1:
>>> count = 1
>>> count = count + 1
>>> count
2
>>> count = count.__add__(1)
>>> count
3
>>>
>>> mylist.__getitem__(1)
66
-Refer to the session in the accompanying Case Study 1. What is the equivalent of the __getItem__ operator?

A) []
B) __add__
C) +
D) =
Question
What keyword defines a class in Python?

A) get
B) construct
C) def
D) class
Question
In Python, the constructor is always named:

A) __get__.
B) __init__.
C) constructor.
D) class.
Question
In a Python class, ____ refers to the object for which the method was called.

A) self
B) init
C) obj
D) class
Question
An accessor method is most likely to be used to implement:

A) mutator methods.
B) information hiding.
C) a constructor.
D) the dot operator.
Question
The print method invokes the ____ method of a class.

A) __print__
B) __str__
C) print
D) out
Question
____ objects store method names that refer to method definitions that are implemented by the class.

A) Mutator
B) Instance
C) Class definition
D) Self
Question
____ methods change an object in some way.

A) Accessor
B) Instance
C) Print
D) Mutator
Question
Preceding an instance variable name by two underscores____ the instance variable.

A) exposes
B) hides
C) mutates
D) accesses
Question
Case Study 2:
1. def createSSandAnimate():
2. ss = SolarSystem(2, 2)
3.
4. sun = Sun("SUN", 5000, 1000, 5800)
5. ss.addSun(sun)
6.
7. m = Planet("MERCURY", 19.5, 1000, .25, 0, 2, "blue")
8. ss.addPlanet(m)
9.
10. m = Planet("EARTH", 47.5, 5000, 0.3, 0, 2.0, "green")
11. ss.addPlanet(m)
12.
13. m = Planet("MARS", 50, 9000, 0.5, 0, 1.63, "red")
14. ss.addPlanet(m)
15.
16. m = Planet("JUPITER", 100, 49000, 0.7, 0, 1, "black")
17. ss.addPlanet(m)
18.
19. numTimePeriods = 2000
20. for aMove in range(numTimePeriods):
21. ss.movePlanets()
22.
23. ss.freeze()
24.
-Refer to the session in the accompanying Case Study 2. Which line(s) perform the actual work of the animation?

A) 4-5
B) 10-11
C) 16-17
D) 19-21
Question
Algorithms describe the solution to a problem in terms of the data needed to represent the problem instance and a set of steps necessary to produce the intended result.
Question
To create an instance of a class, call the __init__ method directly.
Question
Each object from a particular class has the same instance variables, but the values of those variables are different, therefore allowing the object to "behave" differently when asked to perform methods.
Question
The __class__ method is used to provide each object with a reference to the class definition object to which it belongs.
Question
The turtle module only allows one turtle to exist simultaneously in the same window.
Question
Match each definition with its term.
-Refers to the values of all instance variables for an object.

A) State
B) Class
C) Mutator method
D) Accessor method
Question
Match each definition with its term.
-Describes what an object will "look" like, what an object knows about itself, and what an object can do.

A) State
B) Class
C) Mutator method
D) Accessor method
Question
Match each definition with its term.
-Describes a procedure that changes an object in some way.

A) State
B) Class
C) Mutator method
D) Accessor method
Question
Match each definition with its term.
-Sometimes referred to as a "getter" method.

A) State
B) Class
C) Mutator method
D) Accessor method
Question
What does it mean to say that "Python supports the object-oriented programming paradigm?"
Question
What are some of the primitive and collection classes built into the Python language?
Question
What is a constructor method?
Question
What are accessor methods?
Question
What are mutator methods?
Question
Explain how method definitions are stored in Python.
Question
Explain the use of special class methods that Python provides.
Question
What is velocity? Provide an example to illustrate.
Question
Provide a high-level overview of the steps needed to create an animation of planets moving around the sun.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/33
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 10: Astronomy: Creating Classes, Writing Constructors, Accessors, Mutators and Special Methods
1
Every Python object is an instance of a(n):

A) data model.
B) class.
C) method.
D) algorithm.
B
2
The details about what an object can do are called:

A) methods.
B) instance data.
C) models.
D) data types.
A
3
Which of the following is one of Python's collection classes?

A) int
B) float
C) bool
D) str
D
4
The ____ operator is used to invoke a method of an object.

A) dot
B) equals
C) dash
D) star
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
5
Case Study 1:
>>> count = 1
>>> count = count + 1
>>> count
2
>>> count = count.__add__(1)
>>> count
3
>>>
>>> mylist.__getitem__(1)
66
-Refer to the session in the accompanying Case Study 1. What is the equivalent of the + operator?

A) __getItem__
B) __add__
C) ++
D) =
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
6
Case Study 1:
>>> count = 1
>>> count = count + 1
>>> count
2
>>> count = count.__add__(1)
>>> count
3
>>>
>>> mylist.__getitem__(1)
66
-Refer to the session in the accompanying Case Study 1. What is the equivalent of the __getItem__ operator?

A) []
B) __add__
C) +
D) =
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
7
What keyword defines a class in Python?

A) get
B) construct
C) def
D) class
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
8
In Python, the constructor is always named:

A) __get__.
B) __init__.
C) constructor.
D) class.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
9
In a Python class, ____ refers to the object for which the method was called.

A) self
B) init
C) obj
D) class
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
10
An accessor method is most likely to be used to implement:

A) mutator methods.
B) information hiding.
C) a constructor.
D) the dot operator.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
11
The print method invokes the ____ method of a class.

A) __print__
B) __str__
C) print
D) out
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
12
____ objects store method names that refer to method definitions that are implemented by the class.

A) Mutator
B) Instance
C) Class definition
D) Self
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
13
____ methods change an object in some way.

A) Accessor
B) Instance
C) Print
D) Mutator
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
14
Preceding an instance variable name by two underscores____ the instance variable.

A) exposes
B) hides
C) mutates
D) accesses
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
15
Case Study 2:
1. def createSSandAnimate():
2. ss = SolarSystem(2, 2)
3.
4. sun = Sun("SUN", 5000, 1000, 5800)
5. ss.addSun(sun)
6.
7. m = Planet("MERCURY", 19.5, 1000, .25, 0, 2, "blue")
8. ss.addPlanet(m)
9.
10. m = Planet("EARTH", 47.5, 5000, 0.3, 0, 2.0, "green")
11. ss.addPlanet(m)
12.
13. m = Planet("MARS", 50, 9000, 0.5, 0, 1.63, "red")
14. ss.addPlanet(m)
15.
16. m = Planet("JUPITER", 100, 49000, 0.7, 0, 1, "black")
17. ss.addPlanet(m)
18.
19. numTimePeriods = 2000
20. for aMove in range(numTimePeriods):
21. ss.movePlanets()
22.
23. ss.freeze()
24.
-Refer to the session in the accompanying Case Study 2. Which line(s) perform the actual work of the animation?

A) 4-5
B) 10-11
C) 16-17
D) 19-21
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
16
Algorithms describe the solution to a problem in terms of the data needed to represent the problem instance and a set of steps necessary to produce the intended result.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
17
To create an instance of a class, call the __init__ method directly.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
18
Each object from a particular class has the same instance variables, but the values of those variables are different, therefore allowing the object to "behave" differently when asked to perform methods.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
19
The __class__ method is used to provide each object with a reference to the class definition object to which it belongs.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
20
The turtle module only allows one turtle to exist simultaneously in the same window.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
21
Match each definition with its term.
-Refers to the values of all instance variables for an object.

A) State
B) Class
C) Mutator method
D) Accessor method
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
22
Match each definition with its term.
-Describes what an object will "look" like, what an object knows about itself, and what an object can do.

A) State
B) Class
C) Mutator method
D) Accessor method
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
23
Match each definition with its term.
-Describes a procedure that changes an object in some way.

A) State
B) Class
C) Mutator method
D) Accessor method
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
24
Match each definition with its term.
-Sometimes referred to as a "getter" method.

A) State
B) Class
C) Mutator method
D) Accessor method
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
25
What does it mean to say that "Python supports the object-oriented programming paradigm?"
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
26
What are some of the primitive and collection classes built into the Python language?
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
27
What is a constructor method?
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
28
What are accessor methods?
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
29
What are mutator methods?
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
30
Explain how method definitions are stored in Python.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
31
Explain the use of special class methods that Python provides.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
32
What is velocity? Provide an example to illustrate.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
33
Provide a high-level overview of the steps needed to create an animation of planets moving around the sun.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 33 flashcards in this deck.