|
1 | 1 | # author = _'Sanjay'
|
2 | 2 |
|
3 | | -class A(object): |
| 3 | +class SampleClass(object): |
4 | 4 |
|
| 5 | + # for name sake, I've defined a default constructor. |
5 | 6 | def __init__(self):
|
6 | 7 | pass
|
| 8 | + |
| 9 | + def add(self, firstNum, secondNum): |
| 10 | + ''' |
| 11 | + @name: add |
| 12 | + @param: firstNum, secondNum |
| 13 | + @desc: Takes two input paramter, adding them and returning |
| 14 | + @return: sum(firstNum, secondNum) |
| 15 | + ''' |
| 16 | + return self.firstNum + self.secondNum |
7 | 17 |
|
8 | | - def add(self, a, b): |
9 | | - print self.a + self.b |
10 | | - |
11 | | - def add(self, a, b, c): |
12 | | - print a + b + c |
| 18 | + |
| 19 | + # this method does the same as above, but the difference is, it takes 3 parameter here. |
| 20 | + def add(self, firstNum, secondNum, thirdNum): |
| 21 | + ''' |
| 22 | + @name : add |
| 23 | + @param: firstNum, secondNum, thirdNum |
| 24 | + @desc: takes three input parameter, adding them and returning |
| 25 | + @return : sum(firstNum, secondNum, threeNum) |
| 26 | + ''' |
| 27 | + return self.firstNum + self.secondNum + self.thirdNum |
13 | 28 |
|
14 | 29 | #Method overloading is not possible
|
15 | 30 | # This is compile time polymorphism.
|
16 | | -x = A() |
| 31 | +x = SampleClass() |
17 | 32 | x.add(1,2,3)
|
0 commit comments