This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Q on Method Invocation !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Q on Method Invocation !!" Watch "Q on Method Invocation !!" New topic

Q on Method Invocation !!

Reshma Shanbhag
Ranch Hand

Joined: Sep 17, 2002
Posts: 204
Hi All,

The output is = b = 0 b = 16.
Please Explain me why its happening so
[ March 27, 2003: Message edited by: Reshma Pai ]

SCJP 1.4, SCWCD 1.4
Rajeshwari Natarajan
Ranch Hand

Joined: Mar 05, 2003
Posts: 67
Both the base class and derived class contructors invoke the method call()..
since it is overridden in the derived class, and u r creating an object of the derived class, the derived class's call() method will be called twice.
The first time, an object of Q05 is not yet created and b value is not initialized to 16.
So 0 is printed.
[ March 27, 2003: Message edited by: Rajeshwari Natarajan ]

regards<br />Rajeshwari. N
Reshma Shanbhag
Ranch Hand

Joined: Sep 17, 2002
Posts: 204
Thank for helping me out Rajeshwari.
Have you checked out Aspose?
subject: Q on Method Invocation !!
It's not a secret anymore!