Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Day_13.md #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Status/Day_13.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ print aSquare.area()

**My Solution: Python 3**

* The following solution is incorrect. The parent class's area method can be accessed if the child class does not have a method by the same name. Here, because we are instantiating the child class and setting the default length value to zero, it is printing out zero and has no relation with the area of the parent class being zero. If we need to access the parent class method, the child class should not have the same name. The interpreter looks for the method in the current class before moving up the hierarchy.

```python
class Shape():
def __init__(self):
Expand All @@ -157,7 +159,25 @@ print(Asqr.area()) # prints 25 as given argument

print(Square().area()) # prints zero as default area
```
```python
''' Solution by 0KvinayK0
'''
class Shape():
def area(self):
return 0

class Square(Shape):
def __init__(self, length):
super().__init__()
self.length = length

def area(self):
return self.length ** 2

sq = Square(5)
print(sq.area()) # Output: 25
print(super(Square, sq).area()) # Output: 0
```
---

# Question 50
Expand Down