LS23 - Introduction to Object-oriented Programming

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

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? 1. p0 2. p1 3. No way to know

2

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

T

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

T

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

T

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

T

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

T

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

T

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

T

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

T

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

T

Assume a class named Point. The following code listing results in a method call and not a constructor call. a: Point = Point(3, 4)

F

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

F


संबंधित स्टडी सेट्स

U5: Agricultural and Rural Land-Use Patterns and Processes

View Set

PSY of Adulthood and Aging Test on Chpt. 5, 6 , 7 and 10

View Set

Science- Valence Electrons/Bonds (for test 5/16-8th Grade)

View Set

chapter 8, chapter 10, chapter 9 life span, chapter 7 thinking, languages, and intelligence, chapter 6 memory

View Set