What's the best way to define the words “class” and “object” to someone who hasn't used them?

前端 未结 29 876
情话喂你
情话喂你 2020-12-13 05:11

My neighbor is taking \"Intro to Java\", and asked me to help explain a few of the first-day concepts. I realized that since I do this everyday, I don\'t have the beginner\

29条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 05:42

    One of the examples I use during my java courses is the Human class.

    Everyone reading this is a Human (I least I hope so !), we all have our differences our resemblances but at the end we're all Human (After all).

    Each Human (known as an instance or object) has specific characteristics such as the eyes color or the voice which are the fields (you called that variables, but the right name would be fields). But the values are different from an Human instance to another.

    There is also a common knowledge, shared with the humanity, principles like the "Pythagorean theorem". This knowledge is common, it can be interpreted as a static field (I know it's an exaggeration) which means that this knowledge is not only contained in one human but in the humanity.

    Every Human can do things such as walking, speaking etc. this is known as method, walking is the same for everyone, but when I walk, not everyone walk. The act of walking only affects the Human instance which does this, but still it's defined by the Human class


    If you want to get deeper in OOP, Teaching OOP to non-programmers

提交回复
热议问题