Why does this class run?

前端 未结 4 1453
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-21 13:13

I\'ve been playing with my codes a little for a while, and this one is not about a bug or anything, but i just don\'t understand why class main() runs without needing to ini

4条回答
  •  醉酒成梦
    2020-12-21 14:14

    main is a class not a function. Thus the code contained in the class declaration runs immediately because all statements are executed as they appear in code. As a method declaration is reached, it's bound to the class as a member, so in a way methods execute as well but are not called.

提交回复
热议问题