1. Which of the four fundamental features of object-oriented programming could be thought of as removing unnecessary details, allowing the user to focus only on what is necessary? (put NA if it applies to none of them) 2. Classes cannot contain multiple attributes without instantiation of multiple objects True False 3. class Cow: def _init_(self,name,age,weight): self.name=name self.age= age self.weight=weight my_cow=Cow('bessie',8,1800) print(f'I have a cow naned {my_cow.name}') Based on the above code, what would print, and why? Error; my_cow was not created properly I have a cow named Bessie; because the code is fine Error; 8 and 1800 were not utilized Error; Cow was not created properly 4. class car(): def _init_(self,name): self.name=name mycar=car("Mysterious Machine") type(mycar) Given this code, what is the type of mycar? 5. Class and object are essentially the same concept True False 6. You find a class that does almost what you need. Inheritance would come to play if you did which of the following? None of these Create a new class from an existing Create a new class but copy/paste the old one Modify the existing class 7. The exclaim method prints out "I'm a car!" even though we didn't create it in our Prius definition. Why would it be able to do this? None of these The method exclaim is a base Python method which it my_car has by default It inherits the method from the car class Car is a subclass which means it can also use that method 8. Which is the best description of how we would add a method to a subclass? We indicate in the parent object 'submethod' so it applies to the subclass When we create a new class from an old one, we can add a method just like we would for a parent None of these We use the method.add built-in function when defining the function 9. Which of the following is NOT true of using super()? If the definition of the parent changes, using super will ensure that the attributes and methods will reflect that change All of these are true It can reduce the amount of code you need to write Using super() undermines the principle of inheritance
1. Which of the four fundamental features of object-oriented
2. Classes cannot contain multiple attributes without instantiation of multiple objects
True | |
False |
3. class Cow:
def _init_(self,name,age,weight):
self.name=name
self.age= age
self.weight=weight
my_cow=Cow('bessie',8,1800)
print(f'I have a cow naned {my_cow.name}')
Based on the above code, what would print, and why?
|
Error; my_cow was not created properly |
|
I have a cow named Bessie; because the code is fine |
|
Error; 8 and 1800 were not utilized |
|
Error; Cow was not created properly |
4. class car():
def _init_(self,name):
self.name=name
mycar=car("Mysterious Machine")
type(mycar)
Given this code, what is the type of mycar?
5. Class and object are essentially the same concept
True | |
False |
6. You find a class that does almost what you need. Inheritance would come to play if you did which of the following?
|
None of these |
|
Create a new class from an existing |
|
Create a new class but copy/paste the old one |
|
Modify the existing class |
7. The exclaim method prints out "I'm a car!" even though we didn't create it in our Prius definition. Why would it be able to do this?
|
None of these |
|
The method exclaim is a base Python method which it my_car has by default |
|
It inherits the method from the car class |
|
Car is a subclass which means it can also use that method |
8. Which is the best description of how we would add a method to a subclass?
|
We indicate in the parent object 'submethod' so it applies to the subclass |
|
When we create a new class from an old one, we can add a method just like we would for a parent |
|
None of these |
|
We use the method.add built-in function when defining the function |
9. Which of the following is NOT true of using super()?
|
If the definition of the parent changes, using super will ensure that the attributes and methods will reflect that change |
|
All of these are true |
|
It can reduce the amount of code you need to write |
|
Using super() undermines the principle of inheritance |
Trending now
This is a popular solution!
Step by step
Solved in 4 steps