2

While reading Herbert Schildt I came across partial implementation where overriding is'nt mandatory , But I fail to understand why do we implement such an interface where we don't override its methods :

interface CallBack{
  void callback();
}

abstract class Incomplete implements Callback {     //Legal
void someMethod();
}

Is there any practical use of such a class or it's just theoretical ?

3 Answers3

1

One use case is a family of classes which all have to implement the callback interface in the same way. So it could be implemented in the abstract superclass and you don't have to handle it in every subclass.

Abstracted classes can't be instantiated, so you would make sure that all subclasses that you will instantiate in you system later handle the callbacks in the same way.

M. Reif
  • 866
  • 7
  • 20
0

Every subclass of Incomplete now have to implement Callback.

ka4eli
  • 5,294
  • 3
  • 23
  • 43
0

The name it self showing that it's abstract, it need not to implement. Where as the subclasses of that abstract class must and must full fill that definition and needs to implement that methods in that interface.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307