Tuesday, 19 June 2018

Python program to demonstrate constructors

#Python program to demonstrate constructors
# declaration of class

class myClass:
    def __init__(self,fName,lName): # Constructor
    # initialization of variable
        self.FirstName = fName
        self.LastName = lName

    def fName(self):
        return self.FirstName

    def lName(self):
        return self.LastName

mcls = myClass("blk","CapHax")
print("First Name : " + mcls.fName())
print("Last Name : " + mcls.lName())

print()
input("Press Enter to exit.")

No comments:

Post a Comment

Popular Posts