PCAP 31 03 PCAP Certified Associate Python Programmer · Free Practice Question Easy
Question 20
Q166 - OOP
A subclass is usually:
-
A
More specialized than its superclass.
-
B
More general than its superclass.
-
C
A twin of its superclass.
Reveal correct answer
Correct answer: A
Explanation
Topic: subclasses
Try it yourself:
- class Person:
- def __init__(self, fname, lname):
- self.firstname = fname
- self.lastname = lname
- class Student(Person):
- def __init__(self, fname, lname, year):
- super().__init__(fname, lname)
- self.graduationyear = year
- x = Student('Paul', 'Wellert', 2021)
Explanation:
The student is more "specialized" than the person.
Not only does he have a firstname and a lastname
but he has also a graduationyear
Q166 (Please refer to this number, if you want to write me about this question.)
A. A subclass in object-oriented programming is typically more specialized than its superclass. This means that it inherits attributes and behaviors from its superclass but can also have additional features or functionalities that are specific to the subclass. This specialization allows for more specific and targeted implementations in the subclass.
B. A subclass is not more general than its superclass in object-oriented programming. The purpose of creating a subclass is to provide a more specialized version of the superclass with additional features or modifications. The subclass can inherit and extend the functionality of the superclass, making it more specific and tailored to certain requirements or use cases.
C. A subclass is not a twin of its superclass in object-oriented programming. While a subclass inherits properties and methods from its superclass, it can also have its own unique characteristics and behaviors. This differentiation between the superclass and subclass allows for customization and extension of functionality in the subclass without affecting the superclass.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
