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

前端 未结 10 441
无人及你
无人及你 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:10

    Your example won't work with Java or Python, so I have corrected and annotated your main

    class C{
      main()
      {
       A a=new A();
       B b=new B();
       a.methodA(); // C says to a that methodA should be executed
       // C says to b that methodB should be executed
       // and b says to C that the result is answer
       answer = b.methodB(); 
      }
    }
    

提交回复
热议问题