Python Chapter 11 Flashcards
25 Questions
100 Views

Python Chapter 11 Flashcards

Created by
@WellReceivedSquirrel7948

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?

<p>superclasses</p> Signup and view all the answers

Each subclass has a method named init that overrides the superclass's init method.

<p>True</p> Signup and view all the answers

How many accessor and mutator methods are needed to complete the class definition in the example?

<p>3 mutator, 3 accessor</p> Signup and view all the answers

In a UML diagram, what would the open arrowhead point to in the given class definition?

<p>vegetable</p> Signup and view all the answers

In a UML diagram depicting inheritance, you only need to write the name of the subclass.

<p>False</p> Signup and view all the answers

In a UML diagram, what does the open arrowhead point to?

<p>the superclass</p> Signup and view all the answers

What is a specialized class called in an inheritance relationship?

<p>a subclass</p> Signup and view all the answers

What is the name of the base class in the provided class definition?

<p>course</p> Signup and view all the answers

What is the name of the subclass in the provided code?

<p>rose</p> Signup and view all the answers

New attributes and methods may be added to a subclass.

<p>True</p> Signup and view all the answers

Of the two classes, Cherry and Flavor, which would most likely be the subclass?

<p>cherry</p> Signup and view all the answers

One problem with using a UML diagram is that there is no way to indicate inheritance.

<p>False</p> Signup and view all the answers

Polymorphism works on any two class methods that have the same name.

<p>True</p> Signup and view all the answers

What does a subclass inherit from a superclass?

<p>attributes and methods</p> Signup and view all the answers

What gives a program the ability to call the correct method depending on the type of object used?

<p>polymorphism</p> Signup and view all the answers

What is the relationship called in which one object is a specialized version of another object?

<p>is a</p> 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.

<p>False</p> 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.

<p>superclass</p> Signup and view all the answers

Which method can you use to determine whether an object is an instance of a class?

<p>isinstance</p> Signup and view all the answers

What is the correct syntax for defining a class 'table' which inherits from 'furniture'?

<p>class table(furniture):</p> Signup and view all the answers

________ allows a new class to inherit members of the class it extends.

<p>inheritance</p> 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.

<p>polymorphism</p> 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 is Vegetable.
  • 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) is Course.
  • In class Rose(Flower):, the subclass is named Rose.
  • 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.

Quiz Team

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.

More Quizzes Like This

Use Quizgecko on...
Browser
Browser