If class C inherits class B. And B has inherited class

Phương Linh

New member
If class C inherits class B. And B has inherited class A. Then while creating the object of class C, what will be the sequence of constructors getting called?
A. Constructor of C then B, finally of A
B. Constructor of A then C, finally of B
C. Constructor of C then A, finally B
D. Constructor of A then B, finally C
 
Answer: d
Explanation: While creating the object of class C, its constructor would be called by default. But, if the class is inheriting some other class, firstly the parent class constructor will be called so that all the data is initialized that is being inherited.
 

Tìm kiếm

Back
Top