What is the difference between Type and Class?

前端 未结 20 2386
梦谈多话
梦谈多话 2020-11-28 01:00

What makes a type different from class and vice versa?

(In the general language-agnostic sense)

20条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 01:33

    Type contains description of the data (i.e. properties, operations, etc),

    Class is a specific type - it is a template to create instances of objects.

    Strictly speaking class is a special concept, it can be seen as a package containing subset of metadata describing some aspects of an object.

    For example in C# you can find interfaces and classes. Both of them are types, but interface can only define some contract and can not be instantiated unlike classes.

    Simply speaking class is a specialized type used to encapsulate properties and behavior of an object.

    Wikipedia can give you a more complete answer:

    • Definition of class
    • Definition of data type

提交回复
热议问题