• 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

Inherited method acting as overriding method

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
in the below code class Example14 is not explicitly overriding method() but none the less it is inheriting method() from it's parent. But how an inherited method can act as overriding method at the same time?



It produces the output as Krishna
 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why'd you think it is acting as an overriding method. You have only one method definition in your implementation. How is method overriding into picture here?

Example14 is implementing IExample2. So Example14 needs to provide an implementation for the method public void method().
But Example14 also extends Example15 and hence Example14 has the public void method() already defined by the virtue of inheritance. Class Example14, hence, has also
fulfilled the requirement that it provide an 'implementation' for public void method().

Implementing an interface method does not mean you are overriding that method. Overriding happens when your class hierarchy has a method definition available but you provide
another definition. In your example there is only one method definition - the inherited one. So there is no overriding here.

Chan.

 
Vikas J Yadav
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chan for your wonderful explanation
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The code for the Example14 class is actually the one above
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic