0
What is the answer?
Q: Class B inherits from class A. The constructor of class A displays "a", while the class B constructor displays "b". What is output to the screen when the code A a = new B(); is run? but why is the output is "ab" instead of "b" ?
4 Respuestas
+ 4
Both constructors are called.When B is contructed also constructor from A is called. This is because B inherites from A.
+ 1
the answer is "ab"
0
object initialisation and destruction are chained (like a stack):
each constructor calls a super (parent) constructor BEFORE executing
each destructor calls a super (parent) destructor AFTER executing
This assures that
- by the time we execute our constructor all our parent data is initialised
- by the time we execute the Object (parent) destructor all child resources are freed
A (parent) <= B <= C
Constructor code execution order : A, B, C
Destructor code execution order: C, B, A
0
ys, cause b will inherent all a and will add to it his own