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

Prashant Yadav4 reputationPosted Aug 1, 2013, 9:26 AM EDT
Abhineet SrivastavaRank #1,890 · 783 reputationPosted Aug 1, 2013, 9:31 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 1, 2013, 9:45 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 1, 2013, 9:52 AM EDT
The output is:
Abhineet SrivastavaRank #1,890 · 783 reputationPosted Aug 1, 2013, 9:58 AM EDT
Now,Its has been clear for me
Abhineet SrivastavaRank #1,890 · 783 reputationPosted Aug 1, 2013, 10:02 AM EDT
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?
VulpesRank #55 · 29.2K reputationPosted Aug 1, 2013, 10:31 AM EDT
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 SrivastavaRank #1,890 · 783 reputationPosted Aug 1, 2013, 10:38 AM EDT
I m saying that what will happen when b Don't inherit class A & We are creating objest like
A a =new B();
VulpesRank #55 · 29.2K reputationPosted Aug 1, 2013, 10:44 AM EDT
Abhineet SrivastavaRank #1,890 · 783 reputationPosted Aug 1, 2013, 10:47 AM EDT
Got it..
Thank you very much!!
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts