在Python 3中定义一个基类Details,它有一个私有对象属
性name;方法setDetails,用于输入name的值;方法
showDetails用于输出name。从基类派生出一个子类:Employee。Employee有私有对象属性company;方法setEmployee,用于输入公司名字;方法setEmployee,用于输出公司名字。【完成对name和company的输入,并显示出他们的值。】
class Details:
__name = ""
def setDetails(self,name):
self.__name = name
def showDetails(self):
return self.__name
class Employee(Details):
__company = ""
def setEmployee(self,company):
self.__company = company
def showEmployee(self):
return self.__company
a = Details()
a.setDetails("huahua")
print(a.showDetails())
b = Employee()
b.setEmployee("Huawei")
print(b.showEmployee())
class Details:
def __init__():
self.name=''
def setDetails(s):
self.name=s
def showDetails():
print(self.name)
class Employee(Details):
def __init__():
self.company=''
def setEmployee(s):
self.company=s
def showEmployee():
print(self.company)
e=Employee()
e.setDetails('123')
e.setEmployee('456')
e.showDetails()
e.showEmployee()