Peer Instruction: Inheritance Multiple Choice QuestionsΒΆ
- dog, cat
- Try again. Dog and cat are both the subclass of animal.
- dog, animal
- Correct! Dog is the subclass of animal.
- animal, dog
- Try again. Dog is the subclass of animal and the question wants the first is subclass.
- dog, tail
- Try again. Tail is a part of the dog but it does not belong to the subclass.
- None of the above
- Try again. There is one answer correct. Try to think about the relationship between category and subcategory.
Q-1: In the following pairs of words, the first is the subclass and the second is the superclass. Which of them is a correct example of inheritance?
- school, building
- Correct! School is the subclass of building.
- school, student
- Try again. School is an object but student is not.
- student, school
- Try again. School is an object but student is not.
- school, computer
- Try again. School is a building but computer is not.
- None of the above
- Try again. There is one answer correct. Try to think about the relationship between category and subcategory.
Q-2: In the following pairs of words, the first is the subclass and the second is the superclass. Which of them is a correct example of inheritance?
- 5
- Try again. A is defined by the first class, which returns self.x. self.x equals to x, so class B inherits A whose value is 5. B(5) = 5 * 2 = 10.
- 10
- Correct! Class B inherits A, whose value is 5. B(5) = 5 * 2 = 10.
- 510
- Try again. A is defined by the first class, which returns self.x. self.x equals to x, so class B inherits A whose value is 5. B(5) = 5 * 2 = 10.
- 105
- Try again. A is defined by the first class, which returns self.x. self.x equals to x, so class B inherits A whose value is 5. B(5) = 5 * 2 = 10.
Q-3: What is the output of this code?
class A(object):
def __init__(self, x):
self.x = x
def __str__(self):
return str(self.x)
class B(A):
def __init__(self, x):
self.x = x * 2
b = B(5)
print(b)
You have attempted of activities on this page