Starting Out with Python 3e Ch 11 Flashcards
25 Questions
100 Views

Starting Out with Python 3e Ch 11 Flashcards

Created by
@DistinctiveDrama

Questions and Answers

What is the general class in the relationship between superclasses and subclasses?

superclass

What is the specialized class in the relationship between superclasses and subclasses?

subclass

What does it mean to say there is an 'is a' relationship between two objects?

When one object is a specialized version of another object.

What does a subclass inherit from its superclass?

<p>All the superclass's attributes.</p> Signup and view all the answers

What is the name of the superclass in the class definition 'class Canary(Bird):'?

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

______ allows a new class to extend an existing class.

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

In an inheritance relationship, which is the general class?

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

In an inheritance relationship, which is the specialized class?

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

Which of these would most likely be the subclass in the relationship between Airplane and JumboJet?

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

What characteristic of object-oriented programming allows the correct version of an overridden method to be called?

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

Which function can be used to determine whether an object is an instance of a class?

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

Polymorphism allows you to write methods in a subclass that have the same name as methods in the superclass.

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

It is not possible to call a superclass's init method from a subclass's init method.

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

A subclass can have a method with the same name as a method in the superclass.

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

Only the init method can be overridden.

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

You cannot use the isinstance function to determine whether an object is an instance of a subclass of a class.

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

What is the name of the superclass in the class definition 'class Tiger(Felis):'?

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

What is an overridden method?

<p>When a subclass method has the same name as a superclass method.</p> Signup and view all the answers

In object-oriented programming, ______ is used to create an 'is a' relationship among classes.

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

Superclasses are also called ______.

<p>base classes</p> Signup and view all the answers

Subclasses are also called ______.

<p>derived classes</p> Signup and view all the answers

Inheritance involves a superclass and a subclass. The superclass is the ______ and the subclass is the ______.

<p>general class, specialized class</p> Signup and view all the answers

You show inheritance in a UML diagram by ______ from the subclass to the superclass.

<p>drawing a line with an open arrowhead</p> Signup and view all the answers

What functionality does polymorphism provide?

<p>Allows subclasses to have methods with the same names as methods in their superclasses.</p> Signup and view all the answers

We can prevent an AttributeError exception from occurring by using the built-in function ______.

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

Study Notes

Inheritance and Object-Oriented Programming

  • Superclass is a general class; subclass is a specialized class.
  • An "is a" relationship indicates that one object is a specific version of another, meaning the specialized object possesses all attributes of the general object, plus extra features.
  • Subclasses inherit all attributes from their superclasses.

Class Definition and Relationships

  • In the class definition class Canary(Bird):, Bird is the superclass while Canary is the subclass.
  • Inheritance allows new classes to extend existing ones by inheriting members.

Identifying Classes

  • The superclass is the general class in an inheritance relationship.
  • The subclass is the specialized class in an inheritance relationship.
  • In the scenario with Airplane and JumboJet, JumboJet would most likely be the subclass of Airplane.

Polymorphism

  • Polymorphism permits the correct overridden method to be executed when a subclass instance invokes it.
  • Methods in a subclass can share the same name as methods in the superclass, enhancing functionality and flexibility.

Instance Checks

  • The isinstance function checks if an object is an instance of a specified class or subclass.
  • It is false to say you cannot call a superclass's __init__ method from a subclass's __init__ method.

Overriding Methods

  • A method in a subclass can have the same name as one in the superclass, creating an overridden method.
  • Not only the __init__ method can be overridden; any method can be.

General Knowledge

  • Superclasses are referred to as base classes; subclasses are often called derived classes.
  • Inheritance is illustrated in UML diagrams with a line that has an open arrowhead pointing from the subclass to the superclass.
  • Polymorphism allows for method name overlap between subclasses and superclasses, enabling correct method calls based on the object type.
  • Using isinstance helps prevent AttributeError by confirming if an object belongs to a specific class or its subclass.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

Test your knowledge of classes in Python with these flashcards from Chapter 11 of 'Starting Out with Python'. Focus on understanding superclasses and subclasses, as well as the 'is a' relationship in object-oriented programming. Perfect for reinforcing key concepts in this chapter.

More Quizzes Like This

Use Quizgecko on...
Browser
Browser