An Abstract class will never be a final class as an abstract class must be extendable.
Explain abstract class and its behaviour?
Abstract class is defined as a solitary entity, so other classes can inherit from it. An abstract class can not be instantiated, only the subclasses of it can have instances. Following is one of the best examples to explain the use of an abstract class and the behavior of it.
04 | public function eat() { |
08 | public function setColor( $c ) { |
13 | class Apple extends Fruit { |
14 | public function eat() { |
19 | class Orange extends Fruit { |
20 | public function eat() { |
Now taste an apple
What’s the taste of it? Obviously it’s apple
Now eat a fruit
What’s the taste of it? It doesn’t make any sense. does it? Which means the class fruit should not be Instantiable . This is where the abstract class comes into play
4 | abstract public function eat() |
6 | public function setColor( $c ) { |
0 comments:
Post a Comment