• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface Implementation Issue

 
Rayan Al-Hammami
Greenhorn
Posts: 2
1
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, first time poster. I love this forum. In the following code snippet, why does the Phone3 class not have implement the doIt() method from the Device interface? I thought an implementing class must provide concrete implementations for the interface's methods.

Code:


Thanks in advance for your help.


Edit:
Nevermind. I managed to find my answer on the forum. Thanks a lot everyone. For future reference, the answer was:
Quote from Roel De Njs:

It can implement this method either directly (implementation defined in the class itself) or indirectly (implementation defined in a class it extends from).
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rayan Al-Hammami,

First of all, a warm welcome to CodeRanch!

Rayan Al-Hammami wrote:In the following code snippet, why does the Phone3 class not have implement the doIt() method from the Device interface? I thought an implementing class must provide concrete implementations for the interface's methods.

True (if the implementing class is not an abstract class)! But as you already have figured out yourself: a class can implement the method either directly (implementation defined in the class itself) or indirectly (implementation defined in a class it extends from).

Hope it helps!
Kind regards,
Roel

PS. Have a cow for searching this forum and answering your own question!
 
Rayan Al-Hammami
Greenhorn
Posts: 2
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Roel! That helps a ton, and yes, I shall continue answering my own questions when possible, to ensure you all can spend time on more important issues, haha. Thanks again!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic