This could be a useless question, Just out of my curiosity.
Why are we forced to add the keyword abstract
in front of abstract method
of abstract class
, when we don't need to add
the keyword in the case of interface
?
The possible answer could be:
As an abstract class may be a mix of concrete and abstract methods,
the 'abstract' keyword is used to identify which method(s) are abstract.
But
When we don't give any body to any methods, and use ;
at the end of a declaration, then what could go wrong if it is considered as an abstract method automatically?
Why we are forced to add the keyword abstract in front of abstract method of abstract class, when we don't need to add the keyword in case of interface.
Within interfaces, all method definitions are implicitly abstract
. You can provide the keyword, though, but there won't be any difference.
Within abstract
classes, however, when you want to denote a method as abstract
, you're required to type the abstract
keyword. This actually makes the code more readable and easy to be understood.
Not all methods in an abstract class need be abstract. In fact, you can have an abstract class without any abstract methods.
On the other hand, all methods defined in an interface
are implicitly public abstract
, and so you can drop the qualifier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With