Suppose we have class-Class A & Class B
Class A Have one Default Constructor & One Paramatrized constructor
Class B Have one Default Constructor & One Paramatrized constructor
If we create the Object of B...What will be the sequence of constructor call..
Kindly Tell Me..
Thanks!!
Loading

Abhineet SrivastavaPosted Aug 1, 2013, 2:47 PM
Got it..
Thank you very much!!
VulpesPosted Aug 1, 2013, 2:44 PM
Abhineet SrivastavaPosted Aug 1, 2013, 2:38 PM
I m saying that what will happen when b Don't inherit class A & We are creating objest like
A a =new B();
VulpesPosted Aug 1, 2013, 2:31 PM
then the output will be:
Hi
Bye
As before A's constructor will run first, followed by B's constructor.
The fact that you're creating an object of type B and assigning a reference to it to a variable of type A makes no difference to the constructor logic.
Abhineet SrivastavaPosted Aug 1, 2013, 2:02 PM
suppose our code is like that-
Class a
{
C.w("Hi")
}
class B
{
c.w("Bye")
}
Class Test
{
A a = New B();
}
Then what will output?
Abhineet SrivastavaPosted Aug 1, 2013, 1:58 PM
Now,Its has been clear for me
VulpesPosted Aug 1, 2013, 1:52 PM
The output is:
VulpesPosted Aug 1, 2013, 1:45 PM
Abhineet SrivastavaPosted Aug 1, 2013, 1:31 PM
Prashant YadavPosted Aug 1, 2013, 1:26 PM