• Post Reply Bookmark Topic Watch Topic
  • New Topic

When Abstract Classes implement interfaces?  RSS feed

 
Gagan Popli
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am confused a little about the following scenario:


In the above scenario, interface ITest has method iTest() and abstract class implements ITest interface. So, basically now, the abstract class should provide the concrete implementation of the iTest() method.
But, compiler did not complain even though the iTest() is not implemented.

So, I have two questions on this :
1) Please help me understand the reason behind compiler not complaining?
2) When would the abstract classes implement interfaces?

Thanks in advance for the help.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the abstract class doesn't implement iTest, it becomes the responsibility of the concrete classes. So any class extending AbstractTest needs to implement any abstract methods defined in AbstractTest (none in this case), any superclasses (also none in this case) and interfaces.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gagan Popli wrote:So, I have two questions on this :
1) Please help me understand the reason behind compiler not complaining?
2) When would the abstract classes implement interfaces?

1. Because it has nothing to complain about. The abstract class HAS provided a concrete implementation for test() (even though it's not obliged to), and the compiler can't possibly know that it isn't what you regard as a "decent" one.

2. Any time you want a 'skeleton implementation'. There are plenty of them in the Java collections framework, just one of which is List → AbstractList.

HIH

Winston
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston, you may have misread the post. The interface has method iTest, not test.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Winston, you may have misread the post. The interface has method iTest, not test.

Oh, right. In which case the "not obliged to" comes into play.

Blind Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!