aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why output is Null ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Why output is Null ?" Watch "Why output is Null ?" New topic
Author

Why output is Null ?

Kaarthick Ramamoorthy
Greenhorn

Joined: Sep 01, 2006
Posts: 23
Hi,

Please clarify the output.

}
Vaibhav Chauhan
Ranch Hand

Joined: Aug 16, 2006
Posts: 115
In your program, Parent constructor calls the method() of Child class because 'child' refers to Child class object and the member variable of Child is not initialized at this time therefore null is output.

hope you got it.
Kaarthick Ramamoorthy
Greenhorn

Joined: Sep 01, 2006
Posts: 23
Could anybody explain the flow of execution and how it prints Null
Vaibhav Chauhan
Ranch Hand

Joined: Aug 16, 2006
Posts: 115
As I have told the flow goes as follows:
1. as Child class object gets crested, its constructor gets called.
2. In the body of Child constructor, before the execution of the first line, Parent constructor gets called.
3. as method() is overridden in Child class, child class object will call overridden method method().
4. but the instance variable of Child class gets initialized just before the first line in the Child constructor is going to be executed(but it gets initilialized only after the completion of the Parent constructor )

therefore output is null.

hope you got it.
Kaarthick Ramamoorthy
Greenhorn

Joined: Sep 01, 2006
Posts: 23
Thank you, Thank You. I got it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why output is Null ?
 
Similar Threads
Please help explain the output
Constructor doubt
Please explain the initialization sequence in this code
Help
Constructor,why displaying null on this program