CMPSC 132 MODULE 3

¡Supera tus tareas y exámenes ahora con Quizwiz!

Consider the following class Time __init__ method: def __init__(self, hour=0, minute=0, second=0): self.hour = hour # 0-23 self.minute = minute # 0-59 self.second = second # 0-59 Which of the following statements is FALSE? A. Class Time's __init__ method specifies hour, minute and second parameters, each with a default argument of 0 B. The self parameter is a reference to the Time object being initialized C. The statements containing self.hour, self.minute and self.second appear to create hour, minute and second attributes for the new Time object (self). However, these statements may actually call methods that implement the class's hour, minute and second properties D. All of the above statements are true

All of the above statements are true

What is the term used to indicate the variables and constants of a class? Data characters Constants Attributes Identifiers

Attributes In Python, the variables inside a class are termed as attributes of the class. It is not a mandatory rule but variables are used to refer to usual variables used in functions or globally. The term is given because the values stored in those variables represent some kind of data related to class

Which of the following best defines a class? Scope of an object Blueprint of an object Instance of an object Parent of an object

Blueprint of an object A class is simply a representation of a type of object. It is the blueprint/template that describes the details of an object

We can implement a pure OOP program without using classes in our code True False

False For a program to be pure object-oriented, everything must be written inside classes

Which definition best describes an object? Overview of a class Instance of itself A data type Instance of a class

Instance of a class An object is an instance of a class. It has its own state, behavior, and identity

Which of the following statements is FALSE? A. Everything in Python is an object B. Just as houses are built from blueprints, classes are built from objects—one of the core technologies of object-oriented programming C. Building a new object from even a large class is simple—you typically write one statement D. All of the above statements are true

Just as houses are built from blueprints, classes are built from objects—one of the core technologies of object-oriented programming Objects are built from classes

If a local class is defined in a function, which of the following is TRUE for an object of that class? Object is accessible outside the function Object can be declared inside any other function Object can be used outside the function Object can be used/accessed/declared locally in that function

Object can be used/accessed/declared locally in that function For an object which belongs to a local class, it is mandatory to declare and use the object within the function because the class is accessible locally within the class only.

Most object-oriented programming languages enable you to encapsulate (or hide) an object's data from code outside of the class. Such data in these languages is said to be ___________ data. Public Protected Private None of the above

Private Private members (attributes and methods) are only accessible within the class that owns them

How are attributes of an object accessed in Python? Using the dot operator (.) Using the assignment operator (=) Using attribute names directly Using pointers

Using the dot operator (.) Using the dot operator after the name of object we can access its attributes c=Dog('Sandy') c.name


Conjuntos de estudio relacionados

Chapter 2- The California State Department of Real Estate

View Set

Patients w/ renal Disorders (chapter. 27)

View Set