Questions and Answers
A subclass may not override any method other than the init method.
False
A superclass inherits attributes and methods from its subclasses without any of them having to be rewritten.
False
An 'is a' relationship exists between a grasshopper and a bumblebee.
False
What are base classes also called?
Signup and view all the answers
Each subclass has a method named init that overrides the superclass's init method.
Signup and view all the answers
How many accessor and mutator methods are needed to complete the class definition in the example?
Signup and view all the answers
In a UML diagram, what would the open arrowhead point to in the given class definition?
Signup and view all the answers
In a UML diagram depicting inheritance, you only need to write the name of the subclass.
Signup and view all the answers
In a UML diagram, what does the open arrowhead point to?
Signup and view all the answers
What is a specialized class called in an inheritance relationship?
Signup and view all the answers
What is the name of the base class in the provided class definition?
Signup and view all the answers
What is the name of the subclass in the provided code?
Signup and view all the answers
New attributes and methods may be added to a subclass.
Signup and view all the answers
Of the two classes, Cherry and Flavor, which would most likely be the subclass?
Signup and view all the answers
One problem with using a UML diagram is that there is no way to indicate inheritance.
Signup and view all the answers
Polymorphism works on any two class methods that have the same name.
Signup and view all the answers
What does a subclass inherit from a superclass?
Signup and view all the answers
What gives a program the ability to call the correct method depending on the type of object used?
Signup and view all the answers
What is the relationship called in which one object is a specialized version of another object?
Signup and view all the answers
When a class inherits another class, it is required to use all the data attributes and methods of the superclass.
Signup and view all the answers
When there are several classes that have many common data attributes, it is better to write a(n) ________ to hold all the general data.
Signup and view all the answers
Which method can you use to determine whether an object is an instance of a class?
Signup and view all the answers
What is the correct syntax for defining a class 'table' which inherits from 'furniture'?
Signup and view all the answers
________ allows a new class to inherit members of the class it extends.
Signup and view all the answers
________ has the ability to define a method in a subclass and then define a method with the same name in a superclass.
Signup and view all the answers
Study Notes
Inheritance in Object-Oriented Programming
- Subclasses may override only the
__init__
method; false statement about overriding other methods. - Superclass does not inherit from subclasses; false statement about attribute and method inheritance.
- An "is a" relationship does not exist between a grasshopper and a bumblebee; false statement.
- Base classes are also referred to as superclasses.
Class Initialization and Methods
- Each subclass contains an
__init__
method that overrides the superclass's method; true statement. - For a superclass named
clock
, three mutator and three accessor methods are required based on its attributes.
UML Diagram Basics
- In UML, an open arrowhead in code like
class Celery(Vegetable):
points to the superclass, which isVegetable
. - Only the subclass name is insufficient in UML diagrams; false statement about this requirement.
- Open arrowhead in a UML diagram represents the superclass.
Class Relationships and Specialization
- A specialized class in inheritance is called a subclass.
- In
class Python(Course):
, the base class (superclass) isCourse
. - In
class Rose(Flower):
, the subclass is namedRose
. - New attributes and methods can indeed be added to a subclass.
General Classifications
- Between Cherry and Flavor, Cherry is likely the subclass due to its specificity.
- Indicating inheritance is a primary function of UML diagrams; false assertion against this purpose.
Concepts of Polymorphism and Inheritance
- Polymorphism applies to class methods sharing the same name across different classes; true statement.
- Subclasses inherit attributes and methods from superclasses.
- The ability to call the correct method based on the object's type is known as polymorphism.
- The relationship where one object is a specialized version of another is termed "is a".
- Classes are not required to use all data attributes and methods from superclasses; false statement on this necessity.
Designing with Superclasses
- For classes with common data attributes, it is better to create a superclass to hold the shared data.
- The
isinstance
method determines if an object is an instance of a specific class. - The correct syntax for a class inheriting from another is
class ChildClass(ParentClass):
. - Inheritance allows a new class to inherit members from the class it extends.
- Polymorphism enables defining methods with the same name in both a subclass and superclass.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge on Python Chapter 11 with these flashcards. Each card presents a statement about subclasses, superclasses, and relationships in object-oriented programming. Determine whether each statement is true or false to reinforce your understanding.