Python Programming - Classes
Exercise : Classes - General Questions
- Classes - General Questions
41.
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?
Answer: Option
Explanation:
The 'my_car' instance represents a specific car object with the make "Toyota," model "Camry," and year 2022.
42.
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?
Answer: Option
Explanation:
The 'my_book' instance represents a specific book object with the title "Python Programming" and author "John Doe."
43.
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?
Answer: Option
Explanation:
'my_rectangle.calculate_area()' represents the calculated area of the specific rectangle object.
44.
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?
Answer: Option
Explanation:
'my_animal.species' represents the specific species attribute of the individual animal object.
45.
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?
Answer: Option
Explanation:
'my_laptop.brand' represents the specific brand attribute of the individual laptop object.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers