File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 202
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: 202
Thank for helping me out Rajeshwari.
I agree. Here's the link:
subject: Q on Method Invocation !!
Similar Threads
Which method is called????