• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding Inheritance  RSS feed

 
sureshkumar settu
Greenhorn
Posts: 16
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I want to know about inheritance

interface I { public void fun(); }

class A implements I { public void fun() {} }

1. class B extends A implements I { }

2. class C extends A { }

In 1 & 2 both are doing same work, that is inheriting fun(). then What is the purpose of using "implements I" in 1.
is there any specific difference in functionality. Please let me know.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

When you say a class implements an interface, then all its subclasses share the same methods and therefore implicitly implement the same interface. It is neither necessary nor harmful to repeat "implements"; it may be beneficial by reminding people about the implementation. There is no difference in functionality.

Try this:
javadoc C.java
. . .
then open the C.html file with a web browser, and you will see a list of implemented interfaces: I.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!