LS23 - Object Oriented Programming

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

12 Terms

1
New cards

A class definition introduces a new data type, or type of object, in your program.

a. True

b. False

a. True

2
New cards

A class defines groupings of related variables called attributes. Each object, or instance, of a class has those attributes.

a. True

b. False

a. True

3
New cards

A method of a class is a special kind of function that all objects (instances) of the class will have available for calling.

a. True

b. False

a. True

4
New cards

Imagine a class named Pasta where the following lines of code are valid:

p0: Pasta = Pasta()

p0.sauce = "marinara" p0.noodle = "spaghetti"

p1: Pasta = Pasta()

p1.sauce = "fettuccine" p1.noodle = "farfalle" print(p1.price())

In the method call to Pasta#price, self would contain a reference to the same Pasta object as which variable above?

a. p0

b. p1

c. No way to know.

b. p1

5
New cards

The first parameter of a method is self and it is given a reference to the object the method was called on.

a. True

b. False

a. True

6
New cards

The constructor of a class is only called once in a program, no matter how many objects of that class are constructed.

a. True

b. False

b. False

7
New cards

The constructor of a class is responsible for initializing the attributes of a new object (instance) before that object is used.

a. True

b. False

a. True

8
New cards

Assume a class named Point. The following code listing results in a method call and not a constructor call.

a: Point = Point(3, 4)

a. True

b. False

b. False

9
New cards

Assume a class named Point. The following code listing results in a constructor call and a method call.

a: Point = Point(1, -1) a.invert()

a. True

b. False

a. True

10
New cards

The name of a constructor in a Python class definition is __init__.

a. True

b. False

a. True

11
New cards

The first parameter of a constructor is self and it is given a reference to the newly constructed object on the heap.

a. True

b. False

a. True

12
New cards

You should assume there is an automatic statement at the end of each constructor which is:

return self

a. True

b. False

a. True