Inheritance in Python

preview_player
Показать описание
#BackCoding

Inheritance is a powerful feature in object oriented programming. It refers to defining a new class with little or no modification to an existing class. The new class is called derived (or child) class and the one from which it inherits is called the base (or parent) class

#programming
#shorts
#python
Рекомендации по теме
Комментарии
Автор

class Person:
def __init__(self, fname, lname):
self.fname=fname
self.lname=lname
def printName():
print(self.fname, self.lname)

class Student(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname)
self.year=year
def welcome(self):
print("Welcome ", self.fname, self.lname, "graduationyear", self.year)

fname=input("Enter First Name :")
lname=input("Enter last Name :")
year=input("Enter graduationyear :")

obj=Student(fname, lname, year)
obj.welcome()

BackCoding