1、类A调用类B的静态方法
class Person(object):
def flying(self):
Plane.fly() # Person类调用Plane类的静态方法
def do_flying(self):
self.plane = Plane()
self.plane.fly()
class Plane(object):
@staticmethod
def fly():
print('i am flying!')
person = Person()
person.flying()
2、类B作为类A方法的形参
class Person(object):
def flying(self, plane):
plane.fly()
class Plane(object):
def fly(self):
print('i am flying!')
plane = Plane()
person = Person()
person.flying(plane)
3、类B作为类A方法的局部变量
class Person(object):
def flying(self):
self.plane = Plane()
self.plane.fly()
class Plane(object):
def fly(self):
print('i am flying!')
person = Person()
person.flying()
网友评论