class Car:#外部类
    class Door:#内部类
        def open(self):
            print('open door')
        
    class Wheel:
        def run(self):
            print('car run')
            
if __name__=="__main__":
    car=Car()#实例化外部类
    backDoor=Car.Door()#实例化内部类 第一种方法

    frontDoor=car.Door()#因为car已经实例化外部类,再次实例化Car的内部类 第二种方法
    backDoor.open()
    frontDoor.open()
    wheel=car.Wheel()#car已经实例化外部类,Wheel()再次实例化内部类
    wheel.run()#调用内部类的方法

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2018-12-04
  • 2022-12-23
  • 2021-06-10
  • 2022-12-23
  • 2022-01-12
猜你喜欢
  • 2021-10-03
  • 2021-08-18
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
相关资源
相似解决方案