Why explicitly write “private”?

前端 未结 8 1768
孤城傲影
孤城傲影 2020-12-17 08:46

As fields are implicitly private, why there is often explicit declaraion used in the books, articles etc.?

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-17 09:14

    Because you write code for maintainability and clarity, ESPECIALLY in code samples. Implicit declarations are there for the compiler, not for the programmer. Failing to explicitly declare the visibility and scope of your variables leaves your intent ambiguous. Is it really that much extra typing?

提交回复
热议问题