Confused with Java Encapsulation Concept

后端 未结 6 1698
抹茶落季
抹茶落季 2021-01-03 06:37

Good day!

I am reading a Java book about encapsulation and it mentioned the getter and setter method.

I\'ve read that to hide the attributes, I must mark my

6条回答
  •  半阙折子戏
    2021-01-03 07:09

    I find the answers above already answering your question. But, I see another issue with your code, which is, a security and data integrity issue. You are filling your class member directly out of the user's input w/o any validations on it. For example, you'd probably want to check that the email address has an xyz@abc.com pattern. A malicious user might also provide a very long string in the input causing unexpected errors.

提交回复
热议问题