Q: What do we say when a class B can extend another class A?
-
A
A is the superclass and B is the subclass
-
B
B is the superclass and A is the subclass
-
C
Both A and B are the superclass
-
D
Both A and B are the subclass
A
Answer:
A
Explanation:
In object-oriented programming, a subclass is a class that is derived from another class, called the superclass. The subclass inherits properties and methods from the superclass and can also have additional properties and methods of its own.
The subclass is also called an extension of the superclass, because it extends the functionality of the superclass with additional features.
For example, consider the following class hierarchy:
class A {
// Properties and methods of class A
}
class B extends A {
// Properties and methods of class B
}
Here, A is the superclass and B is the subclass. B is derived from A and inherits all of the properties and methods of A. B can also have additional properties and methods of its own.
In this example, A is the superclass and B is the subclass. In the scenario you described, A would also be the superclass and B would be the subclass.
Related Topic:
Share Above MCQ