且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java DOT运算符的目的是什么?

更新时间:2022-06-12 04:30:55

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

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.

对象类之外的代码必须使用对象引用或表达式,然后使用点(.)运算符,然后使用简单的字段名称,如

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() 来调用方法 great() 对象 p p.value 上的strong>用于访问实例变量 .

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.

参考: https://docs.oracle.com/javase/tutorial/java/javaOO/usingobject.html

完整参考书,由赫伯特·希尔德(Herbert Schildt)撰写

The Complete Reference, Book by Herbert Schildt