• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Khalid question...

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

options:

1.9
2.18
3.20
4.21
5.22

Ans: 5 -->22.

can anyone explain how???

Shafi.

[ July 25, 2005: Message edited by: Mohamed Shafi ]
[ July 25, 2005: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rekha & Barry for your reply.


Regards,

Shafi.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
reply
    Bookmark Topic Watch Topic
  • New Topic