m0_71250704 2022-06-15 06:30 采纳率: 25%
浏览 73
已结题

求python程序代码和运行结果

在Python 3中定义一个基类Details,它有一个私有对象属
性name;方法setDetails,用于输入name的值;方法
showDetails用于输出name。从基类派生出一个子类:Employee。Employee有私有对象属性company;方法setEmployee,用于输入公司名字;方法setEmployee,用于输出公司名字。【完成对name和company的输入,并显示出他们的值。】

  • 写回答

2条回答 默认 最新

  • A Python 萌新花花 2022-06-15 06:42
    关注
    
    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())
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

问题事件

  • 系统已结题 6月22日
  • 已采纳回答 6月15日
  • 创建了问题 6月15日