• 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

Interface gives more polymorphism?

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

Interface gives more polymorphism rather than extending a single class ?



I came to know about that in interface all methods are public (must) so there is no ristriction in interface for methods like simple class where we apply other access specifiers(Private,Protected,Default) so interface gives us more polymorphism than single inherited class....

Please rectify the above statement and let me know

 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interfaces by definition cannot have any method implementations but the method signature and are implicitly public.

santhosh.R gowda wrote:so interface gives us more polymorphism than single inherited class....



Polymorphism is the ability to have the super type reference refer to any sub type of that. And using interfaces makes it more flexible that you are able to replace any implementation of the interface at runtime so the runtime system take care of the actual object being refered. You may invoke any method defined in the interface without knowing the actual implementation.
 
A tiny monkey bit me and I got tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic