• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interface gives more polymorphism?  RSS feed

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • 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

 
Vijitha Kumara
Bartender
Posts: 4002
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!