Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

method Overriding

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!
can someone explain in detail what is geing checked at compile time at waht is being done at run time well my version is
that at compile time its checked wheather eat method is in MAmmal . then at runtime the actual object h denotes is of class Cattle.
so the eat() of Cattle shoulb be called.also c is of type Cattle so it should print Cattle version


thanx.
madhur.
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Madhur:
Please note following:
1. eat() is NOT overridding in derived classes as arguments are of different types in each eat().
2. h is of M type but holds C type object.
3. h.eat(c) is passing C type object to eat method. That particular method ( eat(C c) ) is not available in M. As it is not in super class (i.e. M), the derived class's ( eat(C c) ) method can not be called.
4. Now M has a method with same name but different argument type. Therefore, that method ( eat(M m) ) is closest to call i.e. ( eat(C c) and it will be invoked. And you get mammal output.
Hope this helps.
Barkat
[ September 11, 2002: Message edited by: Barkat Mardhani ]
[ September 11, 2002: Message edited by: Barkat Mardhani ]
 
My cellmate was this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic