本文介绍了Java DOT运算符,它实际上做了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我Java DOT操作员实际上做了什么吗?

Can somebody tell me what Java DOT operator actually do?

例如,

class Person{

int value;
public void great(){...};
...
}

Person p = new Person();

Person.great();  <--- here

Person.value;   <--- here

我想知道什么是。操作员这样做,它可以让我很好()或价值。

I want to know what is "." operator doing so that it can get me great() or value.

谢谢

推荐答案

点运算符,也称为分隔符或句点,用于将变量或方法与引用变量分开。

The dot operator, also known as separator or period used to separate a variable or method from a reference variable.

只能访问静态变量或方法使用类名。

Only static variables or methods can be accessed using class name.

在对象类之外的代码必须使用对象引用或表达式,后跟点(。)运算符,后跟一个简单的字段名称in

Code that is outside the object's class must use an object reference or expression, followed by the dot (.) operator, followed by a simple field name as in

objectReference.fieldName

我们使用对象引用来调用对象的方法。将方法的简单名称附加到对象引用,使用插入点运算符(。),如

We use the object reference to invoke an object's method. Append the method's simple name to the object reference, with an intervening dot operator (.) as in

objectReference.methodName(argumentList);

在上述代码中, p.great() 可用于在对象 p great() 方法em> p.value 用于访问实例变量

In the above mentioned code, p.great() can be used to invoke the method great() on object p and p.value is used to access the instance variable value.

参考:

完整参考,Herbert Schildt的书

The Complete Reference, Book by Herbert Schildt

这篇关于Java DOT运算符,它实际上做了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:25