Filters
Question type

Study Flashcards

When a programmer calls the next function on an iterator object, what happens if there is no current item in the sequence?


A) the previous item is returned
B) the compiler generates an error
C) a StopIteration exception is raised
D) the None item is returned

E) B) and D)
F) A) and C)

Correct Answer

verifed

verified

What is one of the primary purposes of using inheritance?


A) to customize an existing class
B) to create code redundancy
C) to avoid creating an __init__ method
D) to duplicate methods in an interface

E) A) and B)
F) A) and D)

Correct Answer

verifed

verified

When implementing the __init__ method in the AbstractBag class, what task should you leave out because it is the responsibility of the subclasses?


A) setting the self.size variable to 0
B) adding items from the source collection
C) initializing the self.items variable
D) checking if a source collection exists

E) B) and C)
F) A) and D)

Correct Answer

verifed

verified

An instance variable that refers to an integer in two different related classes is a likely candidate to be moved to an abstract class.

A) True
B) False

Correct Answer

verifed

verified

When creating the AbstractCollection class, which methods must you modify to provide default behavior?


A) __len__ and count
B) __str__ and __eq__
C) isEmpty and add
D) __init__ and __len__

E) All of the above
F) A) and D)

Correct Answer

verifed

verified

A class that uses lists can use the methods defined in the AbstractCollection class.

A) True
B) False

Correct Answer

verifed

verified

A class that inherits properties from another class is called a superclass.

A) True
B) False

Correct Answer

verifed

verified

Which of the following is true about abstract classes?


A) they are the same as a class interface
B) the are always a subclass of a superclass
C) they are not normally instantiated in client applications
D) they are used as concrete classes by client applications

E) C) and D)
F) All of the above

Correct Answer

verifed

verified

How is creating a subclass of an existing class different from copying the code from the existing class to a new file?


A) delete all the methods that don't have to change
B) you don't need an __init__ method
C) the name of the subclass is in parentheses of the class header
D) no methods need be created or modified

E) A) and B)
F) A) and C)

Correct Answer

verifed

verified

In which situation is a search unnecessary when performing the add method on a sorted bag?


A) when the bag is full
B) when the new item is less than the last item
C) when the new item is greater than the first item
D) when the bag is empty

E) A) and B)
F) All of the above

Correct Answer

verifed

verified

Showing 41 - 50 of 50

Related Exams

Show Answer