@@ -9,12 +9,16 @@ class Vehicle(object):
9
9
10
10
def __init__ (self , name ):
11
11
self .name = name
12
+
13
+ def __str__ (self , * args , ** kwargs ):
14
+ return "Vehicle class" + self .name
15
+ # return object.__str__(self, *args, **kwargs)
12
16
13
- def move (self , distance = 1 ):
17
+ def move (self , distance = 1 ):
14
18
raise NotImplementedError ()
15
19
16
20
def capabilities (self ):
17
- return ["moveable" ,]
21
+ return ["moveable" , ]
18
22
19
23
# ---------------------------
20
24
# inheritance
@@ -23,23 +27,24 @@ def capabilities(self):
23
27
class Car (Vehicle ):
24
28
25
29
def __init__ (self , make , name ):
26
- #Call base class constructor
30
+ # Call base class constructor
27
31
Vehicle .__init__ (self , name )
28
32
self .make = make
29
33
30
- def move (self , distance = 1 ): # overriding base class method
34
+ def move (self , distance = 1 ): # overriding base class method
31
35
print "%s-%s moved %d feet" % (self .make , self .name , distance )
32
36
33
37
def capabilities (self ):
34
- parent_capabilities = Vehicle .capabilities (self ) # super method call
35
- my_capabilities = ["fuel-using" ,"transporter" ]
38
+ parent_capabilities = Vehicle .capabilities (self ) # super method call
39
+ my_capabilities = ["fuel-using" , "transporter" ]
36
40
return parent_capabilities + my_capabilities
37
41
38
42
39
43
# ---------------------------
40
44
# Instantiate no new needed
41
45
# ---------------------------
42
46
car = Car ("Mercedes" , "SL500" )
47
+ print car
43
48
44
49
# ---------------------------
45
50
# access methods with . notation
@@ -50,4 +55,4 @@ def capabilities(self):
50
55
# ---------------------------
51
56
# access properties with . notation
52
57
# ---------------------------
53
- print car .name
58
+ print car .name
0 commit comments