When designing a class, what is one of the first tasks that need to be done? correct answers
Specifying the public interface
Which name would be best for a private instance variable? correct answers _confidential
Which of the following method headers represent a constructor? correct answers def
__init__(self) :
What is the name of the instance variable in the following code segment?
class Fruit :
def getColor(self) :
return self._color correct answers _color
What is the purpose of an object's instance variables? correct answers Store the data required for
executing its methods
Suppose you have a class ShoppingList, with instance variables _quantity, _cost, and
_itemName, how can you access these variables in your program? correct answers Use a method
provided by the ShoppingList class
Consider the following class:
class Counter :
def getValue(self) :
return self._value
def click(self) :
self._value = self._value + 1
def unClick(self) :
, self._value = self._value - 1
def reset(self) :
self._value = 0
Which method is an accessor? correct answers getValue
Which of the following is a purpose of a method? correct answers To access the instance
variables of the object on which it acts
Consider the following code segment which constructs two objects of type Fruit:
x = Fruit()
y = Fruit("Banana", "Yellow")
Which constructor header will construct both objects successfully? correct answers def
__init__(self, name="", color="") :
Which method below would be considered an accessor method? correct answers getCount()
Consider the following class:
class Counter :
def getValue(self) :
return self._value
def click(self) :
self._value = self._value + 1
def unClick(self) :
self._value = self._value - 1
def reset(self) :
self._value = 0
Which method(s) are mutators? correct answers Only click, unClick and reset