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 Khalid question... 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 "Khalid question..." Watch "Khalid question..." New topic

Khalid question...

Mohamed Shafi
Ranch Hand

Joined: Apr 18, 2005
Posts: 119



Ans: 5 -->22.

can anyone explain how???


[ July 25, 2005: Message edited by: Mohamed Shafi ]
[ July 25, 2005: Message edited by: Barry Gaunt ]

Regards,<br /> <br />Shafi.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I'll give you a hint: just follow the basic rules of object construction, bearing in mind that polymorphism is playing a part in the calls to method add in the constructors.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Rekha Gaikwad
Ranch Hand

Joined: Jul 25, 2005
Posts: 36
Hi Mohamed,
I think the progran will work like below.

When u create an object of Extension in bogo method,

1. it will first call constructor of Extension()
2. Which in turn call super() constructor i.e Base constructor
3. Base constructor will call add(1) method. But Acoording to java run time system it will call the method of runtime object which is Extension so it will call add method of Extension which return value of i=2
4.Then control transfer to Extesion class and call add(2) method which leds value i=6
5. After that b.add(8) method will call which will return value i=22.
Mohamed Shafi
Ranch Hand

Joined: Apr 18, 2005
Posts: 119
Thanks Rekha & Barry for your reply.


Prasanta Chinara
Ranch Hand

Joined: Jul 20, 2005
Posts: 30
Don't you think its little weired that even before the object is constructed, the polymorphism comes to play ?

The object is still being constructed .. how could the vtable (standard implementation for overriding function) be constructed properly?
I agree. Here's the link:
subject: Khalid question...
It's not a secret anymore!