Search Header Logo
DCS2103- Week 12 (Objects and Classes)

DCS2103- Week 12 (Objects and Classes)

Assessment

Presentation

Computers

University

Practice Problem

Medium

Created by

Yasmin Basiran

Used 1+ times

FREE Resource

39 Slides • 11 Questions

1

media

2

media

3

Word Cloud

What is one thing you remember from Object Oriented Programming?

4

5

media

6

media

7

media

8

media

9

media

10

media

11

Multiple Choice

What is a class in Python?

1
A class in Python is a type of variable that stores data only.
2
A class in Python is a function that performs calculations.
3
A class in Python is a method for handling exceptions.
4
A class in Python is a blueprint for creating objects that encapsulate data and functionality.

12

Multiple Choice

Which keyword is used to create a class?

1
define
2
function
3
create
4
class

13

media

14

media

15

media

16

media

17

media

18

media

19

media

20

media

21

media

22

Multiple Choice

What does self refer to?

1
A method to initialize class variables.
2
The instance of the class in object-oriented programming.
3
A keyword for defining global variables.
4
A reference to the parent class in inheritance.

23

Multiple Choice

What is the output?
class A:

x = 5

a1 = A()

a2 = A()

print(a1.x, a2.x)

1
5 4
2
4 5
3
5 5
4
5 6

24

Multiple Choice

What will happen if a class has no init?

1
The class will automatically inherit from a parent class.
2
The class will raise an error due to missing parameters.
3
The class will use a default constructor, and instance variables may not be initialized.
4
The class will have all instance variables set to zero.

25

Multiple Choice

What is the purpose of str?

1
To parse strings into data types.
2
To convert objects to their string representation.
3
To format strings for display purposes.
4
To concatenate multiple strings together.

26

Multiple Choice

What happens if you modify a class variable using the class?

1
Modifying a class variable using the class affects all instances of that class.
2
Modifying a class variable only affects the current instance.
3
Changing a class variable has no impact on other instances.
4
Class variables cannot be modified directly from the class.

27

Multiple Choice

Calling an instance method from the class without passing an object causes:

1

ValueError

2

TypeError

3

NameError

4

No error

28

media

29

media

30

media

31

media

32

media

33

media

34

media

35

media

36

media

37

media

38

media

39

media

40

media

41

media

42

media

43

media

44

media

45

media

46

media

47

Multiple Choice

Which method lets you modify class attributes?

1

Class methods (@classmethod)

2

Static methods (@staticmethod)

3
Instance methods
4
Abstract methods

48

Open Ended

Explain the difference between instance variables and class variables using a real-life example.

49

Feature

Instance Variable

Class Variable

Belongs to

Each object individually

The class itself

Shared among objects

No

Yes

Example

Student's name, grade

School name, total students

Changes affect

Only that object

All objects

50

media
media

Show answer

Auto Play

Slide 1 / 50

SLIDE