Free Practice Quiz Question List

2 Classes and Objects Online Quiz Questions

Use this free practice quiz with 20 questions to review 2 Classes and Objects, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

Which statement best distinguishes a class from an object in object-oriented programming?

  1. A

    A class is a reusable definition, while an object is a concrete instance.

  2. B

    A class is always a single runtime value, while an object defines a type.

  3. C

    A class stores only methods, while an object stores only attributes.

  4. D

    A class and an object are two names for the same concept.

02
Choose one
1 point

What happens when Python evaluates checking = BankAccount("Maya", 500) and savings = BankAccount("Maya", 2000)?

  1. A

    They create one BankAccount object with two variable names.

  2. B

    They create two separate BankAccount instances.

  3. C

    They create two classes that share the same balance.

  4. D

    They create one class attribute for each variable.

03
Choose one
1 point

In the expression checking.withdraw(100), what kind of class-defined element is withdraw?

  1. A

    attribute

  2. B

    constructor

  3. C

    method

  4. D

    reference

04
Choose all
1 point

Select all statements that correctly describe attributes in a class-based program.

  1. A

    An instance attribute can hold a value specific to one object.

  2. B

    A class attribute is necessarily copied into a separate independent value for every instance.

  3. C

    A class attribute can represent a value shared by instances.

  4. D

    An instance attribute must have the same value in every object of the class.

05
Choose all
1 point

After checking = BankAccount("Maya", 500) followed by checking.deposit(150), which two results are supported by the material? Select all that apply.

  1. A

    The class definition is replaced.

  2. B

    The checking object's state changes.

  3. C

    The owner attribute is automatically changed.

  4. D

    The balance attribute is updated.

06
True or false
1 point

In Python, __init__() is called automatically after a new instance has been created to establish its initial state.

  1. A

    True

  2. B

    False

07
True or false
1 point

The assignment alias = account creates an independent copy of the object referenced by account.

  1. A

    True

  2. B

    False

08
Written response
1 point

What is the technical term for the collection of an object's attribute values at a particular moment?

09
Written response
1 point

What term describes an object's individuality or whether two references designate the exact same object?

10
Fill in the blank
1 point

An object is an of a class, and creating that object is called .

11
Fill in the blank
1 point

In the example where currency = "USD" is declared in the class body, currency is a .

12
Open ended
1 point

Consider this code:

first = BankAccount("Maya", 500)

second = BankAccount("Maya", 500)

third = first

Explain why first is second is False while first is third is True.

13
Choose one
1 point

For the Rectangle class, what does small.area() return after small = Rectangle(3, 4) and then small.scale(2)?

  1. A

    12

  2. B

    24

  3. C

    48

  4. D

    96

14
True or false
1 point

In Python, an instance method's conventionally named self parameter represents the instance on which the method is called.

  1. A

    True

  2. B

    False

15
Written response
1 point

What programming term describes the collection of an object's attribute values at a particular moment?

16
Written response
1 point

Given the class definition Temperature with to_fahrenheit() returning self.celsius * 9 / 5 + 32, what value does Temperature(20).to_fahrenheit() return?

17
Choose one
1 point

What does the expression BankAccount("Maya", 500) produce when the class has the initializer shown in the material?

  1. A

    A new class definition named BankAccount

  2. B

    A concrete BankAccount object with owner Maya and balance 500

  3. C

    A method named BankAccount without any stored data

  4. D

    A shared class attribute containing the value 500

18
Choose one
1 point

A BankAccount class uses currency = "USD" and assigns self.owner and self.balance in __init__(). Which design best matches the roles of these attributes?

  1. A

    Store currency, owner, and balance only as class attributes

  2. B

    Store currency as a class attribute and owner and balance as instance attributes

  3. C

    Store currency as an instance attribute and owner and balance only as class attributes

  4. D

    Store all three values outside the class because attributes cannot hold account data

19
Choose one
1 point

Using the Rectangle class from the material, what does small.area() return after small = Rectangle(3, 4) followed by small.scale(2)?

  1. A

    12

  2. B

    24

  3. C

    48

  4. D

    96

20
Choose one
1 point

Given first = BankAccount("Maya", 500), second = BankAccount("Maya", 500), and third = first, what are the results of first is second and first is third?

  1. A

    Both expressions evaluate to True because the objects have the same owner and balance

  2. B

    Both expressions evaluate to False because each variable has a different name

  3. C

    first is second is False, while first is third is True

  4. D

    first is second is True, while first is third is False