Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend AND implement in the same class

How can I implement an interface AND extend a class to the same class?

This doesn't seem to work (the interface is not implemented at all):

public class StrongChecker extends BasicChecker implements Checker {

This doesn't work either (the interface is not implemented at all):

public class StrongChecker extends BasicChecker {

And this gives me an error:

public class StrongChecker implements Checker extends BasicChecker {

Thanks for your help !

like image 208
Koen Avatar asked Nov 01 '25 10:11

Koen


2 Answers

There is nothing wrong with:

public class StrongChecker extends BasicChecker implements Checker {

Of course, your StrongChecker class has to implement all the methods of Checker (or inherit implementations from BasicChecker), or the code won't compile.

like image 50
Eran Avatar answered Nov 03 '25 00:11

Eran


There is nothing wrong with this syntax:

public class StrongChecker extends BasicChecker implements Checker {

This is perfectly fine just make sure you actually implement all the methods that need implementation in your interface or you will get an error.

like image 37
brso05 Avatar answered Nov 03 '25 02:11

brso05