Exercise: Classes
Questions for: Classes
Consider the following Python code:
class Laptop:
def __init__(self, brand, model):
self.brand = brand
self.model = model
# Create an instance of the Laptop class
my_laptop = Laptop("Dell", "XPS 13")
# What does the 'my_laptop.brand' represent?
A:
Laptop class
B:
Dell class
C:
XPS 13 class
D:
An individual laptop object
Answer: B
'my_laptop.brand' represents the specific brand attribute of the individual laptop object.
Consider the following Python code:
class Animal:
def __init__(self, species):
self.species = species
# Create an instance of the Animal class
my_animal = Animal("Lion")
# What does the 'my_animal.species' represent?
A:
Animal class
B:
Lion class
C:
An individual animal object
D:
A specific species of animal
Answer: D
'my_animal.species' represents the specific species attribute of the individual animal object.
Discuss About this Question.
Consider the following Python code:
class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def calculate_area(self):
return self.length * self.width
# Create an instance of the Rectangle class
my_rectangle = Rectangle(5, 8)
# What does the 'my_rectangle.calculate_area()' represent?
A:
The Rectangle class
B:
The area of a rectangle
C:
A specific length of a rectangle
D:
An individual rectangle object
Answer: B
'my_rectangle.calculate_area()' represents the calculated area of the specific rectangle object.
Discuss About this Question.
Consider the following Python code:
class Book:
def __init__(self, title, author):
self.title = title
self.author = author
# Create an instance of the Book class
my_book = Book("Python Programming", "John Doe")
# What does the 'my_book' instance represent?
A:
Book class
B:
Python Programming class
C:
John Doe class
D:
An individual book object
Answer: D
The 'my_book' instance represents a specific book object with the title "Python Programming" and author "John Doe."
Discuss About this Question.
Consider the following Python code:
class Car:
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
# Create an instance of the Car class
my_car = Car("Toyota", "Camry", 2022)
# What does the 'my_car' instance represent?
A:
Car class
B:
Toyota class
C:
Camry class
D:
An individual car object
Answer: D
The 'my_car' instance represents a specific car object with the make "Toyota," model "Camry," and year 2022.
Discuss About this Question.
Ad Slot (Above Pagination)
Discuss About this Question.