what its mean by class, object, instance, attribute in object oriented programing ?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 08:05:43

问题


i have learned class is a blueprint of structurally identical items, and the items created using class are called instances. please let me know what are the difference between class, object, instance and attribute in object oriented programming concept. is the object, instance, attribute same?

http://en.wikipedia.org/wiki/Class_(computer_programming)


回答1:


Typically they are used like so:

  • class - blueprint for creating object instances; defines properties and methods
  • object - synonymous with instance usually (sometimes improperly equated with class)
  • instance - an actual manifestation of a class; the class defines what properties and methods the instance has while the instance holds the values of the object attributes
  • attribute - typically synonymous with "property" (an object member whose value can be set), but in some dynamic languages this can also include "methods" (an object member which can be called)



回答2:


Yes, you're definition of a class is correct. You can create multiple objects of the same class. Each object is an instance of the class. The term instance can not only mean the object is an instance of the class, but it can also relate to polymorphism. There is a keyword, in java it is called instanceof. With it, you can not only tell if an object is an instance of the class, but if the object is an instance of a superclass. So, instance, can also be more type-oriented. Attributes are members of the class, like its variables.



来源:https://stackoverflow.com/questions/24744847/what-its-mean-by-class-object-instance-attribute-in-object-oriented-programin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!