This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Khalid question...  RSS feed

 
Mohamed Shafi
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • 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 ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • 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.
 
Rekha Gaikwad
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Rekha & Barry for your reply.


Regards,

Shafi.
 
Prasanta Chinara
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!