0
Polymorphism
if we declare one constructor in parent class and another constructor in child class eg. class A // parent class { public A() { Console.Writeline("I m in A"); } } class B : A // child class { public B() { Console.Writeline("I m in B "); } static void main(string[] args) { A a=new B(); } } output // I m in A I m in B In the above program why it is called both constructor ? explain
3 Respuestas
+ 5
When a sub/child class is instantiate, it will first call the superclass (which is also base class/parent class) constructor, then follow by the sub class' constructor. This can easily remembered and logic as you need the "base"(base class) before you can do anything more (sub class)
+ 5
Btw, this is true for Java, not sure for other languages...
0
thank you