类、对象和实例的区别 [英] The difference between Classes, Objects, and Instances

查看:28
本文介绍了类、对象和实例的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 中的类、对象和实例是什么?

What is a class, an object and an instance in Java?

推荐答案

Java(和任何其他编程语言)是根据类型建模的.在理论层面上,是一些信息量的表示,而类型是一组值.当我们说值 X 是类型 Y 的实例时,我们只是说 X 是类型 Y 的值集的成员.

Java (and any other programming language) is modeled in terms of types and values. At the theoretical level, a value is a representation for some quantum of information, and a type is a set of values. When we say value X is an instance of type Y, we are simply saying that X is a member of the set of values that is the type Y.

这就是实例"一词的真正含义:它描述的是一种关系而不是事物.

So that's what the term "instance" really means: it describes a relationship not a thing.

Java 编程语言的类型系统支持两种类型,原始类型引用类型.引用类型进一步分为数组类型.Java object 是引用类型的实例.

The type system of the Java programming language supports two kinds of types, primitive types and reference types. The reference types are further divided into the classes and array types. A Java object is an instance of a reference type.

一个对象是一个类实例或一个数组.(JLS 4.3.1)

An object is a class instance or an array. (JLS 4.3.1)

这就是类型理论的观点.

That's the type theoretic view.

在实践中,大多数 Java 开发人员将实例"和对象"这两个词视为同义词.(这包括我,然后我试图快速解释一些事情.)大多数开发人员使用值"而不是实例"这个词来指代原始类型的实例.

In practice, most Java developers treat the words "instance" and "object" as synonyms. (And that includes me then I'm trying to explain something quickly.) And most developers use the word "value" rather than "instance" to refer to an instance of a primitive type.

这篇关于类、对象和实例的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆