1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
|
{
"metadata": {
"name": "",
"signature": "sha256:d3cc78f10810f320519cd1c8becefb4790578385b5c2b528dc88273651f18c12"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h1>Chapter 14: Inheritance<h1>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.1, Page Number: 333<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"class road_vehicle:\n",
" def __init__(self):\n",
" self.__wheels=None\n",
" self.__passengers=None\n",
" def set_wheels(self,num):\n",
" self.__wheels=num\n",
" def get_wheels(self):\n",
" return self.__wheels\n",
" def set_pass(self,num):\n",
" self.__passengers=num\n",
" def get_pass(self):\n",
" return self.__passengers\n",
"\n",
"#Define a truck\n",
"class truck(road_vehicle):\n",
" def __init__(self):\n",
" self.__cargo=None\n",
" def set_cargo(self,size):\n",
" self.__cargo=size\n",
" def get_cargo(self):\n",
" return self.__cargo\n",
" def show(self):\n",
" print \"wheels: \",self.get_wheels()\n",
" print \"passengers: \",self.get_pass()\n",
" print \"cargo capacity in cubic feet: \",self.__cargo\n",
" \n",
"#Define an enum type\n",
"(car,van,wagon)=(1,2,3)\n",
"type=[\"car\",\"van\",\"wagon\"]\n",
" \n",
"#Define an automobile\n",
"class automobile(road_vehicle):\n",
" def __init__(self):\n",
" self.car_type=None\n",
" def set_type(self,t):\n",
" self.car_type=t\n",
" def get_type(self):\n",
" return self.car_type\n",
" def show(self):\n",
" print \"wheels: \",self.get_wheels()\n",
" print \"passengers: \",self.get_pass()\n",
" print \"type: \",\n",
" if self.get_type()==1:\n",
" print \"car\"\n",
" elif self.get_type()==2:\n",
" print \"van\"\n",
" elif self.get_type()==3:\n",
" print \"wagon\"\n",
" \n",
"#Variable declaration\n",
"t1=truck()\n",
"t2=truck()\n",
"c=automobile()\n",
"\n",
"t1.set_wheels(18)\n",
"t1.set_pass(2)\n",
"t1.set_cargo(3200)\n",
"\n",
"t2.set_wheels(6)\n",
"t2.set_pass(3)\n",
"t2.set_cargo(1200)\n",
"\n",
"t1.show()\n",
"t2.show()\n",
"\n",
"c.set_wheels(4)\n",
"c.set_pass(6)\n",
"c.set_type(van)\n",
"\n",
"c.show() \n",
" "
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"wheels: 18\n",
"passengers: 2\n",
"cargo capacity in cubic feet: 3200\n",
"wheels: 6\n",
"passengers: 3\n",
"cargo capacity in cubic feet: 1200\n",
"wheels: 4\n",
"passengers: 6\n",
"type: van\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.2, Page Number: 335<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"class base:\n",
" def __init__(self):\n",
" self.__i=self.__j=None\n",
" def set(self,a,b):\n",
" self.__i=a\n",
" self.__j=b\n",
" def show(self):\n",
" print self.__i,self.__j\n",
" \n",
"class derived(base):\n",
" def __init__(self,x):\n",
" self.__k=x\n",
" def showk(self):\n",
" print self.__k\n",
" \n",
"#Variable declaration\n",
"ob = derived(3)\n",
"\n",
"ob.set(1,2) #access member of base\n",
"ob.show() #access member of base\n",
"\n",
"ob.showk() #uses member of derived class\n",
" "
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"1 2\n",
"3\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.3, Page Number: 337<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"class base:\n",
" def __init__(self):\n",
" self.__i=self.__j=None #These act as protected members\n",
" def set(self,a,b):\n",
" self.__i=a\n",
" self.__j=b\n",
" def show(self):\n",
" print self.__i,self.__j\n",
" \n",
"class derived(base):\n",
" def __init__(self):\n",
" self.__k=None\n",
" def setk(self):\n",
" self.__k=self._base__i*self._base__j #accessing private variables in derived class\n",
" def showk(self):\n",
" print self.__k\n",
" \n",
"#Variable declaration\n",
"ob = derived()\n",
"\n",
"ob.set(2,3) #OK, known to be derived\n",
"ob.show() #OK, known to be derived\n",
"\n",
"ob.setk()\n",
"ob.showk() #uses member of derived class\n",
" "
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"2 3\n",
"6\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.4, Page Number: 338<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"class base:\n",
" def __init__(self):\n",
" self.__i=None\n",
" self.__j=None\n",
" def set(self,a,b):\n",
" self.__i=a\n",
" self.__j=b\n",
" def show(self):\n",
" print self.__i,self.__j\n",
" \n",
"class derived1(base):\n",
" def __init__(self):\n",
" self.__k=None\n",
" def setk(self):\n",
" self.__k=self._base__i*self._base__j\n",
" def showk(self):\n",
" print self.__k\n",
"\n",
"class derived2(derived1):\n",
" def __init__(self):\n",
" self.__m=None\n",
" def setm(self):\n",
" self.__m=self._base__i-self._base__j\n",
" def showm(self):\n",
" print self.__m\n",
" \n",
" \n",
"#Variable declaration\n",
"ob1 = derived1()\n",
"ob2 = derived2()\n",
"\n",
"ob1.set(2,3) #access member of base\n",
"ob1.show() #access member of base\n",
"ob1.setk() #uses member of derived1 class\n",
"ob1.showk() #uses member of derived1 class\n",
"\n",
"ob2.set(3,4) #access member of base\n",
"ob2.show() #access member of base\n",
"ob2.setk() #access member of derived1 class\n",
"ob2.setm() #access member of derived2 class\n",
"ob2.showk() #uses member of derived1 class\n",
"ob2.showm() #uses member of derived1 class\n",
" "
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"2 3\n",
"6\n",
"3 4\n",
"12\n",
"-1\n"
]
}
],
"prompt_number": 11
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.5, Page Number: 341<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"class base:\n",
" def __init__(self):\n",
" self.__i=None\n",
" self._j=None\n",
" self.k=None\n",
" def seti(self,a):\n",
" self.__i=a\n",
" def geti(self):\n",
" return i\n",
" \n",
"class derived(base):\n",
" def setj(self,a):\n",
" self._j=a\n",
" def setk(self,a):\n",
" self.k=a\n",
" def getj(self):\n",
" return self._j\n",
" def getk(self):\n",
" return self.k\n",
" \n",
"#Variable declaration \n",
"ob=derived()\n",
"\n",
"ob.setk(10)\n",
"print ob.getk(),\n",
"ob.setj(12)\n",
"print ob.getj()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"10 12\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.6, Page Number: 342<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"class base1:\n",
" def __init__(self):\n",
" self.x=None\n",
" def showx(self):\n",
" print self.x\n",
" \n",
"class base2:\n",
" def __init__(self):\n",
" self.y=None\n",
" def showy(self):\n",
" print self.y\n",
" \n",
"class derived(base1,base2):\n",
" def set(self,i,j):\n",
" self.x=i\n",
" self.y=j\n",
" \n",
"#Variable declaration\n",
"ob = derived()\n",
"\n",
"ob.set(10,20) #provided by derived\n",
"ob.showx() #from base1\n",
"ob.showy() #from base2\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"10\n",
"20\n"
]
}
],
"prompt_number": 17
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.7, Page Number: 343<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"class base:\n",
" def __init__(self):\n",
" print \"Constructing base\"\n",
" def __del__(self):\n",
" print \"Destructing base\"\n",
"\n",
"class derived(base):\n",
" def __init__(self):\n",
" base.__init__(self)\n",
" print \"Constructing derived\"\n",
" def __del__(self):\n",
" print \"Destructing derived\"\n",
" for b in self.__class__.__bases__:\n",
" b.__del__(self)\n",
"\n",
"#Variable declaration\n",
"ob=derived()\n",
"\n",
"#Does nothing but construct and destruct ob"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Constructing base\n",
"Constructing derived\n",
"Destructing derived\n",
"Destructing base\n"
]
}
],
"prompt_number": 19
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.8, Page Number: 344<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"class base:\n",
" def __init__(self):\n",
" print \"Constructing base\"\n",
" def __del__(self):\n",
" print \"Destructing base\"\n",
"\n",
"class derived1(base):\n",
" def __init__(self):\n",
" base.__init__(self)\n",
" print \"Constructing derived1\"\n",
" def __del__(self):\n",
" print \"Destructing derived1\"\n",
" super(derived1,self).__del__(self)\n",
"\n",
"class derived2(derived1):\n",
" def __init__(self):\n",
" derived1.__init__(self)\n",
" print \"Constructing derived2\"\n",
" def __del__(self):\n",
" print \"Destructing derived2\"\n",
" super(self.__class__,self).__del__(self)\n",
" \n",
"#Variable declaration\n",
"ob=derived2()\n",
"\n",
"#Does nothing but construct and destruct ob"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.9, Page Number: 345<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"class base1:\n",
" def __init__(self):\n",
" print \"Constructing base1\"\n",
" def __del__(self):\n",
" print \"Destructing base1\"\n",
" \n",
"class base2:\n",
" def __init__(self):\n",
" print \"Constructing base2\"\n",
" def __del__(self):\n",
" print \"Destructing base2\"\n",
" \n",
"class derived(base1,base2):\n",
" def __init__(self):\n",
" for b in self.__class__.__bases__:\n",
" b.__init__(self)\n",
" print \"Constructing derived\"\n",
" def __del__(self):\n",
" print \"Destructing derived\"\n",
" for b in self.__class__.__bases__:\n",
" b.__del__(self)\n",
" \n",
"#Variable declaration\n",
"ob = derived()\n",
"\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Constructing base1\n",
"Constructing base2\n",
"Constructing derived\n",
"Destructing derived\n",
"Destructing base1\n",
"Destructing base2\n"
]
}
],
"prompt_number": 21
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.10, Page Number: 347<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"class base:\n",
" def __init__(self,x):\n",
" self._i=x\n",
" print \"Constructing base\"\n",
" def __del__(self):\n",
" print \"Destructing base\"\n",
"\n",
"class derived(base):\n",
" def __init__(self,x,y):\n",
" base.__init__(self,y)\n",
" self.__j=x\n",
" print \"Constructing derived\"\n",
" def __del__(self):\n",
" print \"Destructing derived\"\n",
" for b in self.__class__.__bases__:\n",
" b.__del__(self)\n",
" def show(self):\n",
" print self._i,self.__j\n",
"\n",
"#Variable declaration\n",
"ob=derived(3,4)\n",
"\n",
"#Result\n",
"ob.show() #shows 4 3"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Constructing base\n",
"Constructing derived\n",
"Destructing derived\n",
"Destructing base\n",
"4 3\n"
]
}
],
"prompt_number": 23
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.11, Page Number: 348<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"class base1:\n",
" def __init__(self,x):\n",
" self._i=x\n",
" print \"Constructing base1\"\n",
" def __del__(self):\n",
" print \"Destructing base1\"\n",
" \n",
"class base2:\n",
" def __init__(self,x):\n",
" self._k=x\n",
" print \"Constructing base2\"\n",
" def __del__(self):\n",
" print \"Destructing base2\"\n",
" \n",
"class derived(base1,base2):\n",
" def __init__(self,x,y,z):\n",
" self.__j=x\n",
" i=0\n",
" for b in self.__class__.__bases__:\n",
" if i==0:\n",
" b.__init__(self,y)\n",
" else :\n",
" b.__init__(self,z)\n",
" i+=1\n",
" print \"Constructing derived\"\n",
" def __del__(self):\n",
" print \"Destructing derived\"\n",
" for b in self.__class__.__bases__:\n",
" b.__del__(self)\n",
" def show(self):\n",
" print self._i,self.__j,self._k\n",
" \n",
"#Variable declaration\n",
"ob = derived(3,4,5)\n",
"\n",
"#Result\n",
"ob.show()\n",
"\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Constructing base1\n",
"Constructing base2\n",
"Constructing derived\n",
"Destructing derived\n",
"Destructing base1\n",
"Destructing base2\n",
"4 3 5\n"
]
}
],
"prompt_number": 25
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.12, Page Number: 348<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"class base1:\n",
" def __init__(self,x):\n",
" self._i=x\n",
" print \"Constructing base1\"\n",
" def __del__(self):\n",
" print \"Destructing base1\"\n",
" \n",
"class base2:\n",
" def __init__(self,x):\n",
" self._k=x\n",
" print \"Constructing base2\"\n",
" def __del__(self):\n",
" print \"Destructing base2\"\n",
" \n",
"class derived(base1,base2):\n",
" def __init__(self,x,y):\n",
" i=0\n",
" for b in self.__class__.__bases__:\n",
" if i==0:\n",
" b.__init__(self,x)\n",
" else :\n",
" b.__init__(self,y)\n",
" i+=1\n",
" print \"Constructing derived\"\n",
" def __del__(self):\n",
" print \"Destructing derived\"\n",
" for b in self.__class__.__bases__:\n",
" b.__del__(self)\n",
" def show(self):\n",
" print self._i,self._k\n",
" \n",
"#Variable declaration\n",
"ob = derived(3,4)\n",
"\n",
"#Result\n",
"ob.show()\n",
"\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Constructing base1\n",
"Constructing base2\n",
"Constructing derived\n",
"Destructing derived\n",
"Destructing base1\n",
"Destructing base2\n",
"3 4\n"
]
}
],
"prompt_number": 26
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.13, Page Number: 351<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"class base:\n",
" def __init__(self):\n",
" self.__i=None\n",
" self.j=self.k=None\n",
" def seti(self,x):\n",
" self.__i=x\n",
" def geti(self):\n",
" return self.__i\n",
"\n",
"class derived(base):\n",
" def __init__(self):\n",
" self.a=None\n",
"\n",
"\n",
"#Variable declaration\n",
"ob=derived()\n",
"\n",
"ob._base__i=10 #Accessing private members of base class\n",
"ob.j=20 #legal because j and k are public variable in base\n",
"ob.k=30\n",
"\n",
"ob.a=40 #legal because a is public in derived class\n",
"ob.seti(10)\n",
"\n",
"#Result\n",
"print ob.geti(),ob.j,ob.a"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"10 20 40\n"
]
}
],
"prompt_number": 28
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.14, Page Number: 354<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"class base:\n",
" def __init__(self):\n",
" self.i=None\n",
"\n",
"#derived1 inherits base\n",
"class derived1(base):\n",
" def __init__(self):\n",
" self.__j=None\n",
" \n",
"#derived2 inherits base\n",
"class derived2(base):\n",
" def __init__(self):\n",
" self.__k=None\n",
"\n",
"#derived3 inherits from both derived1 and derived2\n",
"class derived3(derived1,derived2):\n",
" def __init__(self):\n",
" self.__sum=None\n",
" \n",
"#Variable declaration\n",
"ob=derived3()\n",
"\n",
"ob.i=10\n",
"ob.j=20\n",
"ob.k=30\n",
"\n",
"ob.sum=ob.i+ob.j+ob.k\n",
"\n",
"#Result\n",
"print ob.i,ob.j,ob.k,ob.sum"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"10 20 30 60\n"
]
}
],
"prompt_number": 29
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>Example 14.15, Page Number: 355<h3>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"class base:\n",
" def __init__(self):\n",
" self.i=None\n",
"\n",
"#derived1 inherits base\n",
"class derived1(base):\n",
" def __init__(self):\n",
" self.__j=None\n",
" \n",
"#derived2 inherits base\n",
"class derived2(base):\n",
" def __init__(self):\n",
" self.__k=None\n",
"\n",
"#derived3 inherits from both derived1 and derived2\n",
"class derived3(derived1,derived2):\n",
" def __init__(self):\n",
" self.__sum=None\n",
" \n",
"#Variable declaration\n",
"ob=derived3()\n",
"\n",
"ob.i=10\n",
"ob.j=20\n",
"ob.k=30\n",
"\n",
"ob.sum=ob.i+ob.j+ob.k\n",
"\n",
"#Result\n",
"print ob.i,ob.j,ob.k,ob.sum"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"10 20 30 60\n"
]
}
],
"prompt_number": 30
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
|