Skip to content

Commit 70e83f1

Browse files
method overriding and is subclass function
1 parent dcf11a6 commit 70e83f1

4 files changed

Lines changed: 58 additions & 11 deletions

File tree

Leetcode/tempCodeRunnerFile.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

OOPS/is_sub_class_function.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Parent Class
2+
class konda:
3+
# Method inside parent class
4+
def reddy(self):
5+
# assigning values to instance variables
6+
self.name = "Konda Reddy"
7+
self.age = 20
8+
9+
10+
# Child Class inheriting from konda
11+
class DerivedClass(konda):
12+
13+
# New method in child class
14+
def konda_re(self):
15+
# assigning value to a new variable
16+
self.na = "Derived Class Variable"
17+
18+
19+
# issubclass(child_class, parent_class)
20+
# This checks whether DerivedClass is derived from konda
21+
22+
print(issubclass(DerivedClass, konda)) # Expected Output: True

OOPS/method_overriding_function.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Parent Class
2+
class konda:
3+
4+
# Parent class method
5+
def reddy(self):
6+
print("This is the Parent class method")
7+
8+
9+
# Child Class inheriting from konda
10+
class DerivedClass(konda):
11+
12+
# Method with the same name as the parent class method
13+
# This overrides the parent method
14+
def reddy(self):
15+
print("This is the Child class method (Method Overriding)")
16+
17+
18+
# Creating object of child class
19+
obj = DerivedClass()
20+
21+
# Calling method
22+
# Since the child class overrides the method,
23+
# the child method will execute instead of parent method
24+
obj.reddy()
25+
26+
27+
# Checking subclass relationship
28+
print(issubclass(DerivedClass, konda)) # Expected Output: True

OOPS/tempCodeRunnerFile.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class konda:
2+
def reddy(self):
3+
self.name=self.name
4+
self.age=self.age
5+
class DerivedClass(konda):
6+
def reddy(self):
7+
self.na=self.na
8+
print(issubclass(konda,DerivedClass))

0 commit comments

Comments
 (0)