i) WAP to understand Classes, objects, Static method and inner class.
class Student:
def __init__(self):
[Link] = int(input('Enter your Roll Number \n'))
[Link] = input('Enter your Name \n')
[Link] = int(input('Enter your Age \n'))
[Link] = input('Enter your Gender \n')
print("")
class Address:
@staticmethod
def display():
print("-------------Inner Class--------------")
print("This is Inner class")
@staticmethod
def statmeth():
print("This is Static method")
def display_record(self):
print("Your Roll number is", [Link])
print("Your Name is", [Link])
print("Your Age is", [Link])
print("Your Gender is", [Link])
print("")
s = Student()
print("")
print("-------------Static Method--------------")
[Link]()
print("")
print("-------------Details of Student are--------------")
s.display_record()
[Link]()
ii) WAP to understand Constructors.
class Student:
def __init__(self, n='', m1=0, m2=0, m3=0, m4=0):
[Link] = input('Enter your name \n')
[Link] = int(input('Enter your History marks \n'))
[Link] = int(input('Enter your Maths marks \n'))
[Link] = int(input('Enter your Science marks \n'))
[Link] = int(input('Enter your Geography marks \n'))
[Link] = ([Link] + [Link] + [Link] + [Link]) / 4
def display_record(self):
print("Hello", [Link])
print("Your Average marks are", [Link])
if [Link] >= 75:
print("You got Distinction class")
elif [Link] >= 60:
print("You got First class")
elif [Link] >= 50:
print("You got Second class")
elif [Link] >= 40:
print("You got Pass class")
else:
print("You are failed")
s = Student()
print("----------------RESULT--------------------")
s.display_record()
iii) WAP to understand Inheritance and Polymorphism with Method overloading and
Method Overriding.
class Student:
def __init__(self):
print("Calling parent constructor")
def teacher(self):
print("Overriding Teacher method in Parent Class")
def s_details(self):
print(".........CALLING PARENT METHOD using Child Object......")
[Link] = input("Enter Your Roll Number -: ")
[Link] = input("Enter Your Name -: ")
[Link] = input("Enter Your Division -: ")
[Link] = input("Enter Your City -: ")
print("Student Details Are.....")
print("Your Roll Number is", [Link])
print("Your Name is", [Link])
print("Your Division is", [Link])
print("Your City is", [Link])
def sum(self, a=None, b=None, c=None):
print(".........METHOD OVERLOADING......")
if a is not None and b is not None and c is not None:
print('Sum of a, b, and c is', a + b + c)
elif a is not None and b is not None:
print('Sum of a and b is', a + b)
else:
print('Sum Not possible.. Value of a is', a)
class College(Student):
def __init__(self):
super().__init__() # Call the parent constructor
print("Calling child constructor")
def teacher(self):
super().teacher() # Call the parent method if needed
print(".........METHOD OVERRIDING: Overriding Teacher method in Child Class")
def c_details(self):
print(".........CALLING CHILD METHOD using Child Object......")
[Link] = input("Enter Your College Name -: ")
[Link] = input("Enter Your University Name -: ")
[Link] = input("Enter Your College City -: ")
print("Your College Details Are.....")
print("Your College name is", [Link])
print("Your University is", [Link])
print("Your College City is", [Link])
c = College()
c.c_details()
c.s_details()
[Link]()
[Link](10, 20, 30)
[Link](10, 20)
[Link](10)