-3

Why one sometimes writes

abstract void etwas();

codcodecode

void etwas()
{
return;
}

Instead of skipping the single declaration? In which cases is it necessary?

radrow
  • 6,419
  • 4
  • 26
  • 53
  • 1
    There is no reason to write etwas() here. – Janny Jan 21 '15 at 13:15
  • 4
    Nobody does that in Java, because it is not valid. It would be if the abstract method was declared in an abstract class, and the concrete method was declared in a subclass of this abstract class. Read http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html – JB Nizet Jan 21 '15 at 13:15
  • 1
    With JB Nizet comment: Person who has written the abstract class has no idea to implement the method. So who ever extends that class has to provide an implementation for the abstract method. Most of the time abstract method gets called by the provider via Abstract class reference, such as call back methods. – sura2k Jan 21 '15 at 13:22

1 Answers1

2

In the same class, this almost never happens.

It happens when you have an abstract class, which defines an abstract method. You do so when you want to make sure that anyone who extends this abstract class, will be forced to provide his own implementation for this abstract method. Otherwise a compile error occurs.

Amr
  • 2,420
  • 2
  • 17
  • 26