chapter 11

Inheritence


# single inheritance
# base class or parent class
'''
class Employee:
    Company = "Google"

    def showDetails(self):
        print("This is an employee")

# Drive class or child class

class Programmer(Employee):
    language = "Python"
    # Company = "YouTube"

    def showDetails(self):
        print("This is an programmer")
    def getlanguage(self):
        print(f"The language is {self.language}")

e = Employee()
p = Programmer()
e.showDetails()
p.showDetails()
p.getlanguage()
print(p.Company)
'''


# multi inheritance 
'''
class Freelanacer:
    company = "Fiver"
    level = 0
    def upgradeLevel(self):
        self.level = self.level + 1

class Employee:
    company = "Visa"
    eCode = 120

class Programmer(Freelanacer,Employee):
    name = "Rohit"

p = Programmer()
p.upgradeLevel()
print(p.level)
print(p.company)
'''

# Multilevel inheritance 
'''
class Person:
    country = "india"
    def takeBreath(self):
        print("I am breathing...")

class Employee(Person):
    company = "Honda"

    def getSalary(self):
        print(f"Salary is {self.salary}")

    def takeBreath(self):
        print("I am an employee, so i am breathing also")

class Programmer(Employee):
    company = "Fiver"
    
    def getSalary(self):
        print(f"No salary to programmer")

    def takeBreath(self):
        print("I am an programmer, so i am breathing ++")



p = Person()
# print(p.company) # it will give you an error because company not given 
e = Employee()
print(e.company)
pr = Programmer()
print(pr.company)
print(pr.country)
'''       


# Super class
'''
class Person:
    country = "india"
    def takeBreath(self):
        print("I am breathing...")

class Employee(Person):
    company = "Honda"

    def getSalary(self):
        print(f"Salary is {self.salary}")

    def takeBreath(self):
        super().takeBreath() 
        print("I am an employee, so i am breathing also")

class Programmer(Employee):
    company = "Fiver"
    
    def getSalary(self):
        print(f"No salary to programmer")

    def takeBreath(self):
        super().takeBreath()
        print("I am an programmer, so i am breathing ++")



p = Person()
p.takeBreath()
e = Employee()
e.takeBreath()
pr = Programmer()
pr.takeBreath()
'''


# Class Meathod
'''
class Employee:
    company = 'Camel'
    salary = 100
    loction = "Delhi"

    # def changeSalary(self, sal):
    #     self.__class__.salary = sal

    @classmethod
    def changeSalary(cls,sal):
        cls.salary = sal

    def changeLoction(cls,loc):
        cls.loction = loc


e = Employee()
print(e.salary)
e.changeSalary(200)
print(e.salary)
e.changeLoction("Mumbai")
print(e.loction)
'''


# getter method and setter meathod
'''
class Employee:
    company = "Bharat gas"
    salary = 5600
    salaryBonus = 400
    # totalSalary = 6000

    @property
    def totalSalary(self):
        return self.salary + self.salaryBonus


    @totalSalary.setter
    def totalSalary(self,val):
        self.salaryBonus = val - self.salary



e = Employee()
print(e.totalSalary)
e.totalSalary = 5800
print(e.salary)
print(e.salaryBonus)
'''


# dunder meathod
'''
class number:
    def __init__(self,num):
        self.num = num


    def __add__(self,num2):
       print("let add it")
       return self.num + num2.num

    def __mul__(self,num2):
       print("let multiply it")
       return self.num * num2.num

n1 = number(4)
n2 = number(6)
sum = n1 + n2
mul = n1 * n2
print(sum)
print(mul)
'''


Comments

Popular posts from this blog

Python chapter 3

Login Page design using Html and CSS only