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

Slides:



Advertisements
Similar presentations
Python Objects and Classes
Advertisements

Object-Oriented Programming
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
F UNCTION O VERLOADING Chapter 5 Department of CSE, BUET 1.
C++ Classes & Data Abstraction
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look 1 Xiang Lian The University of Texas – Pan American Edinburg,
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 11 Classes and Object- Oriented Programming.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation - a language mechanism for restricting access to some.
ASP.NET Programming with C# and SQL Server First Edition
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
CSCI/CMPE 4341 Topic: Programming in Python Chapter 6: Lists, Tuples, and Dictionaries – Exercises Xiang Lian The University of Texas – Pan American Edinburg,
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
The University of Texas – Pan American
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam II Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Introduction To Classes Chapter Procedural And Object Oriented Programming Procedural programming focuses on the process/actions that occur in a.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
CSCI/CMPE 4341 Topic: Programming in Python Review: Final Exam Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 5: Functions – Exercises Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Classes C++ representation of an object
Default Constructors A default constructor is a constructor that takes no arguments. If you write a class with no constructor at all, C++ will write a.
Chapter 3: Using Methods, Classes, and Objects
Introduction to Classes
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Class: Special Topics Copy Constructors Static members Friends this
The University of Texas – Pan American
The University of Texas – Pan American
Introduction to Classes
Chapter 3 Introduction to Classes, Objects Methods and Strings
The University of Texas – Pan American
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Review: Exam I
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises UTPA – Fall 2012 This set of slides is revised from.
The University of Texas – Pan American
The University of Texas – Pan American
The University of Texas – Pan American
The University of Texas Rio Grande Valley
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects – Exercises UTPA – Fall 2012 This set of slides is revised.
The University of Texas – Pan American
CSCI 6307 Foundation of Systems – Exercise (1)
The University of Texas – Pan American
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 6307 Foundation of Systems – Exercise (5)
CSCI 4333 Database Design and Implementation – Exercise (1)
Presentation transcript:

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

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

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

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

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

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

8

9