Page 2 of 2

Re: ทำความรู้จักกับภาษา python (42) : ภาษา python (ไพทอน) แบบ OOP-Object-oriented (โอโอพี-ออบเจ็ค-โอเรียนเทด)

Posted: 09/06/2020 10:22 am
by bolue

Code: Select all

class Employee:

    empcount = 0

    def __init__(self, name, salary):
        self.name = name
        self.salary = salary
        Employee.empcount += 1

    def disempcount(self):
        print("Total %d" % Employee.empcount)

    def disEmployee(self):
        print("Name:", self.name, "salary:", self.salary)

obj1 = Employee("Bow", 18000)

obj2 = Employee("Bow2", 20000)

obj3 = Employee("Bow3", 25000)

obj1.disEmployee()
obj2.disEmployee()
obj3.disEmployee()
print("Total %d" % Employee.empcount)
ผลลัพธ์
Python Knowledge-1.png
Python Knowledge-1.png (6.02 KiB) Viewed 171 times