How exactly do “Objects communicate with each other by passing messages”?

前端 未结 10 450
无人及你
无人及你 2021-01-30 17:34

In several introductory texts on Object-oriented programming, I\'ve come across the above statement.

From wikipedia, \"In OOP, each object is capable of receivi

10条回答
  •  悲&欢浪女
    2021-01-30 18:04

    What you have posted will not compile in any oop language, as methodB does not belong to object A and methodA doesn't belong to object B.

    If you called the correct method, then both of these are message passing by object C:

    a.methodA();
    b.methodB();
    

    From wikipedia:

    The process by which an object sends data to another object or asks the other object to invoke a method.

提交回复
热议问题