File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ [ <-- Return to index] ( ../README.md )
2
+ # Inheritance/Extension
3
+
4
+ ### How are classes inherited/extended?
5
+ #### PHP
6
+ Classes are extended by use of the ` extends ` keyword.
7
+ ``` php
8
+ <?php
9
+ class myClass {
10
+ private $foo;
11
+ public function setFoo($value) {
12
+ $this->foo = $value;
13
+ }
14
+ }
15
+
16
+ class myOtherClass extends myClass {
17
+ public $bar;
18
+ public function baz() {
19
+ print "This is a unique method that myClass doesn't have";
20
+ }
21
+ }
22
+ ?>
23
+ ```
24
+ #### Python
25
+ Classes are inherited as they are defined:
26
+ ``` python
27
+ class myClass :
28
+ foo = 1
29
+ def setFoo (value ):
30
+ self .foo = value
31
+
32
+ class myOtherClass (myClass ):
33
+ bar = " apples"
34
+ def baz ():
35
+ print " This method is unique to myOtherClass and isn't in myClass"
36
+ ```
You can’t perform that action at this time.
0 commit comments