@@ -18,21 +18,21 @@ In Python, abstract methods can only declare what methods are required in the ob
18
18
Abstract classes can be defined in the following way:
19
19
``` php
20
20
<?php
21
- abstract class myAbstractClass {
22
- abstract protected function foo();
23
-
21
+ abstract class myAbstractClass {
22
+ abstract protected function foo();
23
+
24
24
public function bar() { // Common method
25
- print "Hello world"
25
+ print "Hello world"
26
26
}
27
27
}
28
28
?>
29
29
```
30
30
And can be implemented in the following way (assuming the previously defined abstract class exists):
31
31
``` php
32
32
<?php
33
- class myConcreteClass extends myAbstractClass {
34
- protected function foo() {
35
- print "This is my implementation of the foo method";
33
+ class myConcreteClass extends myAbstractClass {
34
+ protected function foo() {
35
+ print "This is my implementation of the foo method";
36
36
}
37
37
}
38
38
?>
@@ -43,14 +43,14 @@ Abstract classes can be created in the following way (Note: the `ABC` class *mus
43
43
from abc import ABC , abstractmethod
44
44
45
45
class myAbstractClass (ABC ):
46
- @abstractmethod
46
+ @abstractmethod
47
47
def foo (self ):
48
- pass
48
+ pass
49
49
```
50
50
And abstract classes can be "implemented" in the following way (assuming the previously defined abstract class exists):
51
51
``` python
52
52
class myClass (myAbstractClass ):
53
- def foo (self ):
54
- print (" This is my implementation of the foo method" )
53
+ def foo (self ):
54
+ print (" This is my implementation of the foo method" )
55
55
```
56
56
If a class that inherits an abstract class is created and does not implement one of the abstract methods, a ` TypeError ` exception will be raised.
0 commit comments