Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.

Similar presentations


Presentation on theme: "CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of."— Presentation transcript:

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

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

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 (); 3

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 4

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. 5

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. 6

7 7

8 8

9 9


Download ppt "CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of."

Similar presentations


Ads by Google