1 / 9

Introduction to Object-Oriented Programming in Python - Exercises

This chapter covers exercises on objects and classes, data encapsulation, and inheritance in Python. Learn about creating objects, constructors, class attributes, and more.

ehannon
Download Presentation

Introduction to Object-Oriented Programming in Python - Exercises

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI/CMPE 4341 Topic: Programming in PythonChapter 7: Introduction to Object-Oriented Programming in Python – Exercises Xiang Lian The University of Texas – Pan American Edinburg, TX 78539 lianx@utpa.edu

  2. Objectives • In this chapter, you will do some exercises about: • Objects and classes • Data encapsulation • Inheritance

  3. Multiple Choice • Object-oriented programming encapsulates data and functions into _______. • A. functions B. attributes C. classes D. files • Method ____ is called the constructor in Python. • A. __del__() B. className() C. __init__ D. __self__ • A class can have __________ object(s). • A. only 1 B. only 2 C. between 1 and 3 D. 1 or more than 1 • Every class declaration contains keyword ____ followed immediately by the class’s name. • A. keyword B. public C. void D. class • Which of the following statements is true to create a new object of class MyClass in Python? • A. MyClass obj = new MyClass () • B. obj = new MyClass ; • C. MyClass *obj = new MyClass (); • D. obj = new MyClass ();

  4. Multiple Choice (cont'd) • A(n) _______ is a variable shared by all objects of a class. • A. object attribute B. class attribute C. object function D. dynamic attribute • With _____, a class is derived from several base classes. • A. single inheritance B. multiple inheritance C. parent class D. data encapsulation • _____ in the first line of a class definition are used to indicate the inheritance. • A. colons B. parentheses C. classes D. square brackets

  5. True or False Statements • Object-oriented programming languages do not use functions to perform actions. • The parameter self must be the first item in a method's argument list. • The class constructor returns an object of the class. • Constructors may specify default arguments. • An attribute that begins with a single underscore is a private attribute. • The destructor is called when the keyword del is used on an object.

  6. True or False Statements (cont'd) • A shared class attribute should be initialized in the constructor. • When invoking an object’s method, a program does not need to pass a value that corresponds to the object reference parameter. • Every class should have a __del__ method to reclaim an object's memory. • The derived class inherits all the attributes and methods of its base class in Python.

More Related